Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Backup a table? 2

Status
Not open for further replies.

pk400i

MIS
Feb 10, 2009
102
US
HI I want to backup a table with 'some' data, not all the data. The developer wants to see all the fields and everything. I did a CSV file but he says this is not what he means.
How does one make such a backup, for SQL Server 2005?
 
You cannot backup just some of the data. It's all or nothing.

The simplest way to backup your database is:

Code:
Backup Database [Your database name here] To Disk = 'C:\MyBackup.bak'

Replace with your database name and run this in a query window.



-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
As George said it is not possible, but you can create Temporary DB, select * from that table and then backup that temp DB. Something like:
Code:
CREATE DATABASE TempBackup
SELECT * INTO TempBackup.dbo.NameOfTable FROM YourDb.dbo.NameOfTable
--- George's code goes here
Backup Database TempBackUp To Disk = 'C:\MyBackup.bak'

DROP DATABASE TempBackup
NOT TESTED!!!!


Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Thank you. I was getting an error message that TempBackup does not exist there on line 2.

CREATE DATABASE TempBackup
SELECT * INTO TempBackup.dbo.rm00101 FROM pbs.dbo.rm00101
Backup Database [Tempbackup] To Disk = 'C:\MyBackup.bak'
Drop Database Tempbackup
 
try putting so GO's in there:

Code:
CREATE DATABASE TempBackup
go
SELECT * INTO TempBackup.dbo.rm00101 FROM pbs.dbo.rm00101
go
Backup Database [Tempbackup] To Disk = 'C:\MyBackup.bak'
go
Drop Database Tempbackup


-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Would it be possible to only copy a set number of rows, something like backup from row n to n?
 
SELECT * INTO TempBackup.dbo.rm00101 FROM pbs.dbo.rm00101
[!]Where row between 10 and 20[/!]

You can add any where clause you want. What I show above is just an example.



-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top