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
 how can we save a table in other database

Author  Topic 

rtutus
Aged Yak Warrior

522 Posts

Posted - 2006-09-11 : 12:10:07
1-I want to save records from a table located in my database1 on Server1 to a non existing table in another database2 in another server2. (The destination table doesn t exist, I want it to be created with T-SQL). How can I do that using T-SQL
2- Also, is there an other better practice to back up my table before I do some dammage inintentially and destroy the table or the records forever or does SQL server do that automatically for us.
Thanks a lot for your advice.

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-09-11 : 12:16:26
1.
SELECT ....
INTO NewTable
FROM ....

NewTable can be in a different database, just use a three part name databasename.ownername.tablename

2. No, SQL Server does not keep copies for you. If you're backing up the database and the transaction log you have a bunch of restore options, but not as simple as just getting back a few rows. You need to either copy to a new table with SELECT ... INTO, or INSERT ... SELECT to use an existing table.
SQL Server 2005 has a very cool new feature called database snapshots that make it much easier too.
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-09-11 : 12:26:00
To export records from a table on db1 on server1 to db2 on server2, you have 3 options:

1) Add server2 as linkedserver to server1 and then using four-part naming, use Select...into syntax
2) Use OPENDATASOURCE() function to temporarily connect to server2 and export records using select...into statement
3) Use more sophisticated tool like DTS

Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-09-11 : 12:32:05
quote:
Originally posted by harsh_athalye

3) Use more sophisticated tool like DTS



That would be your opinion

I would bcp the data and bcp it in to the other database's table



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

rtutus
Aged Yak Warrior

522 Posts

Posted - 2006-09-11 : 12:32:25
Thank you
Go to Top of Page
   

- Advertisement -