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 |
|
bondwiththebest
Starting Member
46 Posts |
Posted - 2008-05-22 : 22:22:24
|
| hi,I was wondering how we can insert new records into a table which has records already. The first col. is an identity col and a primary key.I have 3000 records and the first col. has unique id but then I need to need to insert new records without inserting all records again. please let me know if you have any ideas. |
|
|
rmiao
Master Smack Fu Yak Hacker
7266 Posts |
Posted - 2008-05-22 : 22:48:10
|
| That's ok since sql will generate value for identity column. You can use insert statement, or load data with bcp/bulk insert if data are in file. |
 |
|
|
bondwiththebest
Starting Member
46 Posts |
Posted - 2008-05-22 : 23:33:35
|
| I forgot to mention my insert statement. IT looks like this insert into tablename(col2,col3.....) select col,.....from table 1join table 2 on ....join table 3 on....col 1 has identiy property.So i am not sure how I can use the update/ inserted statement over here to insert only new records from those select tables. Thats where I got stuck. I cant compare with destination tables values becasue it will null. I am not sure how i can include in the select statement to get only new records!! |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-05-23 : 00:51:59
|
| INSERT INTO Table1 (Column2, Column3)SELECT Column2, Column3FROM Table2 t2WHERE NOT EXISTS (SELECT * FROM Table1 t1 WHERE t1.Column1 = t2.Column1)Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Database maintenance routines:http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx |
 |
|
|
|
|
|