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 2005 Forums
 Transact-SQL (2005)
 Move table to another database

Author  Topic 

temperature
Starting Member

5 Posts

Posted - 2008-06-21 : 10:56:44
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 - 2008-06-21 : 10:59:03
both databases are on the same server...
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-06-21 : 11:22:35
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!
Go to Top of Page

temperature
Starting Member

5 Posts

Posted - 2008-06-21 : 11:38:26
thanks. that is exactly what i was looking for.

bye
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-06-21 : 12:39:25
You have to copy indexes and constraints as it won't get copied.
Go to Top of Page
   

- Advertisement -