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 |
|
Linok
Starting Member
34 Posts |
Posted - 2008-03-27 : 13:20:55
|
Hey Everyone,I'm trying to copy the data from one table to another while preserving the identity keys, but I can't seem to get past this error message. Here's the SQL:SET IDENTITY_INSERT dbo.Cms_MenuItems_Preview ONINSERT INTO dbo.Cms_MenuItems_PreviewSELECT Id, [Name], Url, Parent, IsActive, SortIndexFROM dbo.Cms_MenuItemsSET IDENTITY_INSERT dbo.Cms_MenuItems_Preview OFF and the error message is: Msg 8101, Level 16, State 1, Line 3An explicit value for the identity column in table 'dbo.Cms_MenuItems_Preview' can only be specified when a column list is used and IDENTITY_INSERT is ON.Any suggestions?Thanks in advance! |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2008-03-27 : 13:44:41
|
| The error message says you have to use a column list.CODO ERGO SUM |
 |
|
|
bfoster
Starting Member
30 Posts |
Posted - 2008-03-27 : 14:44:21
|
| Make changes to match your table definition as appropriate, but it means you need to do something like this on the INSERT INTO line.SET IDENTITY_INSERT dbo.Cms_MenuItems_Preview ONINSERT INTO dbo.Cms_MenuItems_Preview(Id, [Name], Url, Parent, IsActive, SorIndex)SELECT Id, [Name], Url, Parent, IsActive, SortIndexFROM dbo.Cms_MenuItemsSET IDENTITY_INSERT dbo.Cms_MenuItems_Preview OFF |
 |
|
|
Linok
Starting Member
34 Posts |
Posted - 2008-03-27 : 15:30:53
|
| duh :-PIt was one of those things where I stared at it for so long, I was missing the obvious.Thanks a lot! |
 |
|
|
|
|
|
|
|