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 |
|
ASP_DRUG_DEALER
Yak Posting Veteran
61 Posts |
Posted - 2004-08-11 : 10:10:35
|
| Hey all-I need to insert into a table, if a record does not alreay exist. My question is what is better to use or is there an even slicker way?IF EXIST(SELECT P_ID, P_YEAR, J_ID FROM PARTS WHERE P_ID=@PIDAND P_YEAR=@YEARAND J_ID=@JOB)--DO NOTHING, BUT IT WILL NOT SCAN THE ENTIRE TABLEELSEBEGININSERT INTO PARTS(THIS THAT THE OTHEREND----OR IS THIS ONE BETTER? @ SOME POINT, THERE MAYBE 10K RECORDS IN TABLE---IF NOT EXIST(SELECT P_ID, P_YEAR, J_ID FROM PARTS WHERE P_ID=@PIDAND P_YEAR=@YEARAND J_ID=@JOB)BEGININSERT INTO PARTS(THIS THAT THE OTHEREND |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-08-11 : 10:17:25
|
| i think that it preety much doesn't matter.Go with the flow & have fun! Else fight the flow :) |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2004-08-11 : 13:10:56
|
| Could you just do the INSERT and ignore the error if it already exists? Might be quicker ... particularly if the INSERT will succeed most of the time.Kristen |
 |
|
|
|
|
|