Solved

how do i set identity on in SQL?

Posted on 2011-09-21
7
273 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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 60

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

627 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