[英]Backup a single table with its data from a database in sql server 2008
I want to get a backup of a single table with its data from a database in SQL Server using a script.我想使用脚本从 SQL Server 中的数据库中获取单个表及其数据的备份。
How can I do that?我该怎么做?
select * into mytable_backup from mytable
制作表mytable的副本,以及其中的每一行,称为mytable_backup 。
You can use the "Generate script for database objects" feature on SSMS.您可以使用 SSMS 上的“为数据库对象生成脚本”功能。
This one solved my challenge.这个解决了我的挑战。
Hope this will help you as well.希望这也能帮助你。
There are many ways you can take back of table.您可以通过多种方式收回餐桌。
You can create table script along with its data using following steps:您可以使用以下步骤创建表脚本及其数据:
For more information, see Eric Johnson's blog.有关更多信息,请参阅Eric Johnson 的博客。
尝试使用以下查询,它将在相同或其他数据库(“数据库”)中创建相应的表。
SELECT * INTO DataBase.dbo.BackUpTable FROM SourceDataBase.dbo.SourceTable
Backup a single table with its data from a database in sql server 2008使用sql server 2008中数据库中的数据备份单个表
SELECT * INTO [dbo].[tbl_NewTable]
FROM [dbo].[tbl_OldTable]
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.
然后,您可以使用常规 SQL Server 内置备份来备份实际上备份表的文件组。
To backup a filegroup see: https://docs.microsoft.com/en-us/sql/relational-databases/backup-restore/back-up-files-and-filegroups-sql-server要备份文件组,请参阅: https : //docs.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要在非默认文件组上创建表(很容易),请参阅:在非默认文件组上创建表
This query run for me ( for MySQL).这个查询为我运行(对于 MySQL)。 mytable_backup must be present before this query run.
mytable_backup 在此查询运行之前必须存在。
insert into mytable_backup select * from mytable
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.
您必须将脚本中的第一行 (USE DatabaseName) 更改/添加到新数据库,以避免出现“数据库已存在”错误。
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.右键单击新创建的数据库,然后单击任务 > 备份...备份将包含来自原始数据库的选定表。
为了在本地文件系统上的文件中获取副本,Windows 开始按钮菜单中的这个摇摇欲坠的实用程序起作用了:“C:\\Program Files (x86)\\Microsoft SQL Server\\110\\DTS\\Binn\\DTSWizard.exe”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.