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 |
|
sparrow37
Posting Yak Master
148 Posts |
Posted - 2010-07-14 : 05:51:41
|
| Hi all,I have table names us states with data( stateid, statename) stateid is primary key and it has values like (1,3,4 etc) I mean they are not in sequence as I deleted some rows and added new. Now I am creating a new database and i created the USStates table with same column names. I want to insert the same data. I created SQL script 'with data' and removed primary key column from the insert statements. and run the insert statesments which added rows in news usstates table. now I need to import data of uscity table from old db to new which has 1000 rows. old database uses old usstates(1,3,4 etc) so when i create and insert data in new uscity table. it is not mapping properly. how can i fix this problem ?Regards,Asif Hameed |
|
|
sql-programmers
Posting Yak Master
190 Posts |
Posted - 2010-07-14 : 05:58:00
|
| SET IDENTITY_INSERT tablename ON and insert the primary key values, then it will inserted like 1,3,4after insert setSET IDENTITY_INSERT tablename OFFSQL Server Programmers and Consultantshttp://www.sql-programmers.com/ |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2010-07-14 : 06:06:03
|
| see this link it will be useful...http://www.sqlteam.com/article/using-the-output-clause-to-capture-identity-values-on-multi-row-inserts |
 |
|
|
|
|
|