Solved

Copy into table with identity insert

Posted on 2011-02-15
5
548 Views
Last Modified: 2012-05-11
How can I run the code below with identity insert  when I copy from the...BU to live?

delete from proc_cfa.dbo.P_AvailableForSale

Select * into proc_cfa.dbo.P_AvailableForSale
from proc_cfa.dbo.P_AvailableForSaleBU
 
0
Comment
Question by:lrbrister
  • 3
5 Comments
 
LVL 51

Expert Comment

by:HainKurt
ID: 34897868
SET IDENTITY INSERT myTable ON;
insert into myTable values (...);
SET IDENTITY INSERT myTable OFF;
0
 
LVL 51

Accepted Solution

by:
HainKurt earned 500 total points
ID: 34897880
oops, _

SET IDENTITY_INSERT myTable ON;
insert into myTable values (...);
SET IDENTITY_INSERT myTable OFF;
0
 
LVL 51

Assisted Solution

by:HainKurt
HainKurt earned 500 total points
ID: 34897894
you can turn it on only for one table at a time:

http://msdn.microsoft.com/en-us/library/aa259221(v=sql.80).aspx
0
 

Author Closing Comment

by:lrbrister
ID: 34897909
Perfect...thanks
0
 
LVL 13

Expert Comment

by:devlab2012
ID: 34897932
Here is the set of queries:

delete from proc_cfa.dbo.P_AvailableForSale


SET IDENTITY_INSERT proc_cfa.dbo.P_AvailableForSale ON

Select * into proc_cfa.dbo.P_AvailableForSale
from proc_cfa.dbo.P_AvailableForSaleBU

SET IDENTITY_INSERT proc_cfa.dbo.P_AvailableForSaleOFF

Note that there is "_" in indetity_insert.
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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.

820 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