2

我有一个用于记录目的的 SQL 表(表中有十万条记录)。我需要清除表(备份数据并需要清除表数据)。

有没有一种标准的方法可以让我自动化它。?

4

2 回答 2

2

您可以在 SQL Server Management Studio 中执行此操作,方法是:

right clicking Database > Tasks > Generate Script

然后,您可以选择要编写脚本的表,还可以选择包含任何关联的对象,例如约束和索引。

附上一张图片,它会给你一步一步的过程,

image_bkp_procedure

PFB stackoverflow 链接,它将让您对此有更多了解,

表级备份

以及您的自动化要求,

您可以下载 bcp 实用程序,该实用程序在 Microsoft SQL Server 实例和用户指定格式的数据文件之间复制数据。要导出的示例语法,

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

您可以使用任何调度机制(UNIX 等)自动执行此查询

于 2012-12-25T18:04:50.677 回答
2
Simply we can create a job that runs once in a month
--> That backups data in another table like archive table
--> Then deletes data in the main table
Its primitive partitioning I guess, this way it will be more flexible when you need to select data from the past deleted one i.e. now on archive table where you have backed up
于 2012-12-26T06:09:16.383 回答