Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 SQL INSERT INTO fails...

Author  Topic 

flamz
Starting Member

21 Posts

Posted - 2008-05-22 : 16:19:43
HI,
I'm trying to perform a SQL SELECT INTO from one database to another, like this:
SELECT * INTO TheTable FROM otherdb.dbo.TheTable.

But I get an error saying that the object "TheTable" already exists.

I need to first create the table that will be filled with data because the SELECT INTO doesn't copy the IDENTITY property of my ID columns.

Any ideas??

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-05-22 : 16:22:12
SET IDENTITY_INSERT TheTable ON

INSERT INTO TheTable (Column1, Column2)
SELECT Column1, Column2
FROM otherdb.dbo.TheTable

SET IDENTITY_INSERT TheTable OFF

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Database maintenance routines:
http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
Go to Top of Page
   

- Advertisement -