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
 Identity insert ON

Author  Topic 

JJ297
Aged Yak Warrior

940 Posts

Posted - 2010-06-04 : 08:43:03
I forgot to turn the identity seed on in a table that has a lot of data in it. I created a new table and tried to copy the data from the old table to the new one where I have the identity seed on. I tried this:

SET IDENTITY_INSERT weeklydiariesnc ON
Insert into weeklydiariesnc
select * from weeklydiariesfile

It's not working. I'm getting:

An explicit value for the identity column in table 'weeklydiariesnc' can only be specified when a column list is used and IDENTITY_INSERT is ON.

What am I doing wrong?

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-06-04 : 09:16:39
SET IDENTITY_INSERT weeklydiariesnc ON
Insert into weeklydiariesnc (col_list)
select * from weeklydiariesfile


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2010-06-04 : 09:35:41
Thank you that's it!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-06-04 : 09:39:04
quote:
Originally posted by JJ297

Thank you that's it!


Points

1 When you use IDENTITY_INSERT ON, you need to list out all the columns
2 When it is off, you need to list out all but identity column

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2010-06-04 : 09:59:16
Thank you for the points. I will remember that for now on.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-06-04 : 10:04:03
quote:
Originally posted by JJ297

Thank you for the points. I will remember that for now on.


You are welcome

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -