Solved

SQL copying tables from one database to another

Posted on 2014-04-24
4
144 Views
Last Modified: 2014-04-24
I have to copy data into tables with incremented identifiers...  I did a select into and then renamed the table, but then SQL 2012 will not allow me to change the column into what was the identifier because it now has data?
0
Comment
Question by:urthrilled
4 Comments
 
LVL 8

Accepted Solution

by:
ProjectChampion earned 167 total points
Comment Utility
use the following method:

SET IDENTITY_INSERT <myTable> ON
insert into <myTable>...
SET IDENTITY_INSERT <myTable> OFF
0
 
LVL 4

Author Comment

by:urthrilled
Comment Utility
So, it looks like that would turn the identity on during copying the data in?

I need to copy about 8500 rows and keep the identifier they currently have
0
 
LVL 13

Assisted Solution

by:magarity
magarity earned 166 total points
Comment Utility
the name of the command does look a little funny at first glance but it means "let me (instead of the system) insert identity values"
0
 
LVL 22

Assisted Solution

by:Steve Wales
Steve Wales earned 167 total points
Comment Utility
The usual behavior is that you can't insert a value into an identity column.

With IDENTITY_INSERT set to ON, you are allowed to insert a value.

See the docs for an example: http://technet.microsoft.com/en-us/library/ms188059.aspx
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

743 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