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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 importing data

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,4

after insert set

SET IDENTITY_INSERT tablename OFF

SQL Server Programmers and Consultants
http://www.sql-programmers.com/
Go to Top of Page

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
Go to Top of Page
   

- Advertisement -