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
 General SQL Server Forums
 New to SQL Server Programming
 Copy tables from one DB to an other?

Author  Topic 

landau66
Yak Posting Veteran

61 Posts

Posted - 2007-12-07 : 04:33:05
Hi everyone!

I want to copy from DB certain tables to an other DB. How can I do that with SQL Server 2005. I would prefer an SQL string solution instead of buttonclicking solution.

Thanks a lot and greetings from Vienna, Austria

landau

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2007-12-07 : 04:46:15
create the table in the second DB. If it is not on the same server, you will need to create a linked server, you can use sp_addlinkedserver for this. Afcter this is done, you can just do:

Insert into Table (<fieldlist>)
select <fieldlist>
from Table
Go to Top of Page

suresha_b
Yak Posting Veteran

82 Posts

Posted - 2007-12-07 : 04:53:29
use AnotherDB
go
select * into dbo.TableName from DB.dbo.TableName
Go to Top of Page

landau66
Yak Posting Veteran

61 Posts

Posted - 2007-12-07 : 04:53:40
The DB is on the same server. It contains about 25 tables. Do I have to create all this tables by hand in the new DB?? Or do I have a copy function or anything like that??

Thanks for your quick answer

landau
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2007-12-07 : 05:16:17
Not if you do not want to, you can use suresha_bs suggestion.
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-12-07 : 23:40:55
suresha_bs' way doesn't copy index nor keys.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-10 : 01:40:16
quote:
Originally posted by landau66

The DB is on the same server. It contains about 25 tables. Do I have to create all this tables by hand in the new DB?? Or do I have a copy function or anything like that??

Thanks for your quick answer

landau


Generate the script of the tables and run it in target db
and then do

Insert into...
select ....

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -