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 2005 Forums
 Transact-SQL (2005)
 Why doesn't Identy insert work

Author  Topic 

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2007-08-03 : 14:42:47
[code]
begin
set identity_insert SpProductionDB.dbo.TSTD_ShortTermDisabilityCheck on
insert into SpProductionDB.dbo.TSTD_ShortTermDisabilityCheck
select *
from SpProductionDBBak.dbo.TSTD_ShortTermDisabilityCheck
set identity_insert SpProductionDB.dbo.TSTD_ShortTermDisabilityCheck off
end
[/code]

Why does this not work, I am getting this error

**
Msg 8101, Level 16, State 1, Line 3
An explicit value for the identity column in table 'SpProductionDB.dbo.TSTD_ShortTermDisabilityCheck' can only be specified when a column list is used and IDENTITY_INSERT is ON.
**

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2007-08-03 : 14:44:51
Turns out I just needed to write out the column names
Go to Top of Page

KenW
Constraint Violating Yak Guru

391 Posts

Posted - 2007-08-03 : 16:19:01
For future reference,

quote:

an only be specified when a column list is used



Means that you need to write out the column names.
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2007-08-06 : 07:15:25
Can we add this to our collection of "Why you do NOT use 'Select *'" ?

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

pootle_flump

1064 Posts

Posted - 2007-08-06 : 09:57:44
quote:
Originally posted by DonAtWork

Can we add this to our collection of "Why you do NOT use 'Select *'" ?

It could have been worse - there might not have been an identity column and it might have worked
Go to Top of Page
   

- Advertisement -