Solved

how do i set identity on in SQL?

Posted on 2011-09-21
7
262 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

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

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

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 …
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

763 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