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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Move table to another database
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

5 Posts

Posted - 06/21/2008 :  10:56:44  Show Profile  Reply with Quote
hello everybody,

how can I move (or copy) a table from one database to another database in ms sql server? does a syntax code exist for that operation.

thanks a lot

Starting Member

5 Posts

Posted - 06/21/2008 :  10:59:03  Show Profile  Reply with Quote
both databases are on the same server...
Go to Top of Page

Cybernetic Yak Master

11752 Posts

Posted - 06/21/2008 :  11:22:35  Show Profile  Visit spirit1's Homepage  Reply with Quote
if table2 doesn't exist in db2:

select <columns here> into db2..table2
from db1..table1

if table2 does exist in db2:

insert into db2..table2 (<columns here> )
select <columns here>
from db1..table1

Causing trouble since 1980
Speed up SSMS development: <- version 1.0 out!

Edited by - spirit1 on 06/21/2008 11:22:47
Go to Top of Page

Starting Member

5 Posts

Posted - 06/21/2008 :  11:38:26  Show Profile  Reply with Quote
thanks. that is exactly what i was looking for.

Go to Top of Page

Flowing Fount of Yak Knowledge

7174 Posts

Posted - 06/21/2008 :  12:39:25  Show Profile  Reply with Quote
You have to copy indexes and constraints as it won't get copied.
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000