This makes a copy of table mytable , and every row in it, called mytable_backup . It will not copy any indices, constraints, etc., just the structure and data.
(Note that this will not work if you have an existing table named mytable_backup , so if you want to use this code regularly (for example, to backup daily or monthly), you'll need to run drop mytable_backup first).
You can use the "Generate script for database objects" feature on SSMS.
Right click on the target database
Select Tasks > Generate Scripts
Choose desired table or specific object
Hit the Advanced button
Under General, choose value on the Types of data to script. You can select Data only, Schema only, and Schema and data. Schema and data includes both table creation and actual data on the generated script.
Another approach you can take if you need to back up a single table out of multiple tables in a database is:
Generate script of specific table(s) from a database (Right-click database, click Task > Generate Scripts...
Run the script in the query editor. You must change/add the first line (USE DatabaseName) in the script to a new database, to avoid getting the "Database already exists" error.
Right-click on the newly created database, and click on Task > Back Up... The backup will contain the selected table(s) from the original database.
To get a copy in a file on the local file-system, this rickety utility from the Windows start button menu worked: "C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\DTSWizard.exe"
7条答案
按热度按时间qkf9rpyu1#
This makes a copy of table
mytable
, and every row in it, calledmytable_backup
. It will not copy any indices, constraints, etc., just the structure and data.(Note that this will not work if you have an existing table named
mytable_backup
, so if you want to use this code regularly (for example, to backup daily or monthly), you'll need to rundrop mytable_backup
first).ghhkc1vu2#
You can use the "Generate script for database objects" feature on SSMS.
jum4pzuy3#
There are many ways you can take back of table.
lzfw57am4#
You can create table script along with its data using following steps:
For more information, see Eric Johnson's blog.
niknxzdl5#
Put the table in its own filegroup. You can then use regular SQL Server built in backup to backup the filegroup in which in effect backs up the table.
To backup a filegroup see: https://learn.microsoft.com/en-us/sql/relational-databases/backup-restore/back-up-files-and-filegroups-sql-server
To create a table on a non-default filegroup (its easy) see: Create a table on a filegroup other than the default
zour9fqk6#
Another approach you can take if you need to back up a single table out of multiple tables in a database is:
dy2hfwbg7#
To get a copy in a file on the local file-system, this rickety utility from the Windows start button menu worked: "C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\DTSWizard.exe"