SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

temperature
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
temp

temperature
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

spirit1
Cybernetic Yak Master

Slovenia
11751 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
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.0 out!

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

temperature
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.

bye
Go to Top of Page

sodeep
Flowing Fount of Yak Knowledge

USA
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  
 New 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.08 seconds. Powered By: Snitz Forums 2000