Groups | Blog | Home
all groups > sql server programming > january 2004 >

sql server programming : importing and maintaining identity columns


Glenn Carr
1/30/2004 10:15:12 PM
I'm would like to import records I select with a SELECT from one database to
another but maintain the identity column values. I've read where I can do
this by setting IDENTITY_INSERT ON. From the Import wizard on the
enterprise manager, I am selecting 'import using a query', then specifying:

SET IDENTITY_INSERT mytable ON; SELECT * FROM mytable WHERE fk_id = nnn; SET
IDENTITY_INSERT OFF;

This isn't working. Can someone tell me how this is done? I'm obviously
inexperienced in this area, but any help would be greatly appreciated.

Thanks,
Glenn

James Hokes
1/30/2004 11:35:19 PM
The error you received was probably the biggest clue.

You can only insert prior identity values into a table with an identity
column if the following conditions are met:

1.) SET IDENTITY_INSERT is ON for the table
2.) You use an explicit column list; "INSERT INTO / SELECT * FROM" will
not work, and the error surely told you so.

The "SELECT *" is alright, you just have to specify the target columns.

James Hokes

[quoted text, click to view]

klod
1/31/2004 12:25:07 AM
Where is your INSERT Statement?

--
Claudio Rivera, MCSD, MCDBA, MCT




[quoted text, click to view]


Glenn Carr
2/1/2004 2:20:03 AM
This was the solution:

[quoted text, click to view]

AddThis Social Bookmark Button