Solved

Copy into table with identity insert

Posted on 2011-02-15
5
518 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
String manipulation 15 49
Copy Database Wizard Error 3 21
c# if statement weird reaction 3 29
Getfiles in vb.net 28 22
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

760 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

18 Experts available now in Live!

Get 1:1 Help Now