Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Table-level backup

How to take table-level backup (dump) in MS SQL Server 2005/2008?

like image 238
user82431 Avatar asked Mar 25 '09 07:03

user82431


People also ask

What are the main 3 types of backups in SQL?

A backup of data in a complete database (a database backup), a partial database (a partial backup), or a set of data files or filegroups (a file backup). A backup of a database.


2 Answers

You cannot use the BACKUP DATABASE command to backup a single table, unless of course the table in question is allocated to it's own FILEGROUP.

What you can do, as you have suggested is Export the table data to a CSV file. Now in order to get the definition of your table you can 'Script out' the CREATE TABLE script.

You can do this within SQL Server Management Studio, by:

right clicking Database > Tasks > Generate Script

You can then select the table you wish to script out and also choose to include any associated objects, such as constraints and indexes.

in order to get the DATA along with just the schema, you've got to choose Advanced on the set scripting options tab, and in the GENERAL section set the Types of data to script select Schema and Data

Hope this helps but feel free to contact me directly if you require further assitance.

like image 95
John Sansom Avatar answered Sep 30 '22 18:09

John Sansom


I am using the bulk copy utility to achieve table-level backups

to export:

bcp.exe "select * from [MyDatabase].dbo.Customer " queryout "Customer.bcp" -N -S localhost -T -E 

to import:

bcp.exe [MyDatabase].dbo.Customer in "Customer.bcp" -N -S localhost -T -E -b 10000 

as you can see, you can export based on any query, so you can even do incremental backups with this. Plus, it is scriptable as opposed to the other methods mentioned here that use SSMS.

like image 27
kenwarner Avatar answered Sep 30 '22 19:09

kenwarner