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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 IDENTITY_INSERT

Author  Topic 

Torch
Starting Member

20 Posts

Posted - 2005-07-14 : 19:41:54
Im trying to execute the following code:

SET @strSQL = 'SET IDENTITY_INSERT ['+@database+'].[dbo].[Group] ON '
+'INSERT INTO [' + @database + '].dbo.[Group] SELECT * FROM #TempGroup '
+'SET IDENTITY_INSERT ['+@database+'].[dbo].[Group] ON'
exec(@strSQL)

However I get the following error message:

Server: Msg 8101, Level 16, State 1, Line 1
An explicit value for the identity column in table 'NGC.2005.dbo.Group' can only be specified when a column list is used and IDENTITY_INSERT is ON.

When I set IDENTITY_INSERT {ON/OFF} in the current database it works perfectly. However when I try and set it for a table in a different database I get the above error.

Any help in this matter would be much appreciated.

Torch.

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-07-14 : 19:44:25
The SELECT * is not allowed for IDENTITY_INSERT (this is essentially what the error message states). You must explicitly list all of the columns like so:

INSERT INTO [Group](col1, col2, col3) ...

And if you have any opportunity to change the name of the Group table, do so.
Go to Top of Page

Torch
Starting Member

20 Posts

Posted - 2005-07-14 : 19:50:12
Thanks, specifying the columns did the trick.

Torch.
Go to Top of Page
   

- Advertisement -