Solved

how do i set identity on in SQL?

Posted on 2011-09-21
7
226 Views
Last Modified: 2012-06-22
i am using the following command:
insert into [wf10taa_test].[dbo].[cutdetail] select * FROM [wf10taa].[dbo].[cutdetail] where cutno = '9701373'

and i am receiving the followig error when i run it:
An explicit value for the identity column in table 'wf10taa_test.dbo.cutdetail' can only be specified when a column list is used and IDENTITY_INSERT is ON.

what i have to do to allow this line to run? and after i finish do i need to set off? how?

Thanks
0
Comment
Question by:gvilbis
7 Comments
 
LVL 21

Accepted Solution

by:
JestersGrind earned 100 total points
Comment Utility
SET IDENTITY_INSERT tablename ON
GO

Do the insert.

SET IDENTITY_INSERT tablename OFF
GO

Greg

0
 
LVL 31

Assisted Solution

by:James Murrell
James Murrell earned 100 total points
Comment Utility
for further info on JestersGrinds comment http://msdn.microsoft.com/en-us/library/ms188059.aspx
0
 

Assisted Solution

by:MightyMirza
MightyMirza earned 100 total points
Comment Utility
SET IDENTITY_INSERT [wf10taa_test].[dbo].[cutdetail] ON
GO

insert into [wf10taa_test].[dbo].[cutdetail] (ColumnName1,ColumnName2,..)
select * FROM [wf10taa].[dbo].[cutdetail] where cutno = '9701373'

SET IDENTITY_INSERT [wf10taa_test].[dbo].[cutdetail] OFF
GO

--the above mentioned code will help you do the insert, and yes you have to set it OFF after the insert (which the above code will take care).
--You were not adding columns after the table name(the table in which the rows has to be inserted)
--Make sure you put in your column names in the above query.

Fahad Mirza


0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:gvilbis
Comment Utility
i did the following but still receiving the same error:
SET IDENTITY_INSERT [wf10taa_test].[dbo].[cutdetail] ON
go
insert into [wf10taa_test].[dbo].[cutdetail] select * FROM [wf10taa].[dbo].[cutdetail] where cutno = '9701373'
SET IDENTITY_INSERT [wf10taa_test].[dbo].[cutdetail] OFF
go


error:
An explicit value for the identity column in table 'wf10taa_test.dbo.cutdetail' can only be specified when a column list is used and IDENTITY_INSERT is ON.

i must to put all the columns names? but i have many columns, is there a shortage way to do it instead to type all the columns names? it will take a long time?

Thanks
0
 
LVL 59

Assisted Solution

by:Kevin Cross
Kevin Cross earned 100 total points
Comment Utility
If this is a test environment, you could (1) restore production to development or (2) remove the identity restriction on column totally from tables in test if you will be replicating the data from production always.
0
 
LVL 75

Assisted Solution

by:Anthony Perkins
Anthony Perkins earned 100 total points
Comment Utility
If you are not explicitly inserting the IDENTITY value than all you need to do is explicitly declare all the columns, as in (there is not need for the SET IDENTITY_INSERT stuff ...) :

INSERT INTO [wf10taa_test].[dbo].[cutdetail] (Col1, Col2, Col3, ...)
SElECT Col1, Col2, Col3, ...
FROM [wf10taa].[dbo].[cutdetail]
WHERE cutno = '9701373'

0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now