Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2007-01-11 : 06:54:53
|
| Srinivas writes "I need to insert multiple records in single table. The structure of the table is Create table DocData(SrNo bigint identity,SourceAppName bigint notnull,SourceDocId bigint notnull)There are around one million records in the table.I am inserting data in this table from frontend developed using VB.In the application, user will enter single value for SourceAppName column and multiple values for SourceDocId column.While inserting i need to make sure that i don't enter duplicate value for column combination i.e.,(sourceAppName,SourceDocId).Can anybody help me and tell the best way to do it without looping through values in table.Can this be accomplished with single insert statement or not.Thanks in advance." |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-01-11 : 07:10:07
|
| [code]IF NOT EXISTS (SELECT NULL FROM DocData WHERE SourceAppName = @SourceAppName AND SourceDocID = @SourceDocID) INSERT INTO DocData (SourceAppName, SourceDocID) VALUES (@SourceAppName, @SourceDocID)[/code]Peter LarssonHelsingborg, Sweden |
 |
|
|
LoztInSpace
Aged Yak Warrior
940 Posts |
Posted - 2007-01-11 : 21:52:09
|
| Don't forget to put a unique constraint on those columns too so you don't stuff it up using other applications. |
 |
|
|
|
|
|