Solved

how do i set identity on in SQL?

Posted on 2011-09-21
7
257 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
ID: 36576015
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
ID: 36576592
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
ID: 36576882
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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

Author Comment

by:gvilbis
ID: 36577632
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
ID: 36577639
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
ID: 36577692
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

809 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