用巨大的表发布脚本(Publish script with huge tables)

编程入门 行业动态 更新时间:2024-10-25 05:27:57
用巨大的表发布脚本(Publish script with huge tables)

我试图在SQL中备份特定的表,但是当发布包含数据的脚本时,脚本太大了。 它已经运行了一个多小时,脚本大小已超过1TB。 即使执行这么大的脚本也是不可能的。

我在SQL中重新创建了这些表的备份,但它只是太大了,我的数据库目录上没有足够的空间。

有没有人对如何备份这些表有任何建议?

Table 1 : 56,370,203 records Table 2 : 35,528,469 records Table 3 : 7,965,568 records

先谢谢你。

I am trying to make a backup of specific tables within SQL but when publishing the script with data included the script is just too big. It has been running now for more that an hour and the script size is already more than a terabyte. Even executing a script this big would be impossible.

I have recreated backups for these tables within SQL but it is just simply too big and I do not have enough space on my DB directory.

Does anyone have any advice on how to make backups of these tables?

Table 1 : 56,370,203 records Table 2 : 35,528,469 records Table 3 : 7,965,568 records

Thank you in advance.

最满意答案

所以,如果你只想保留某些表的状态然后稍后恢复它,那就是我要做的:

1)创建另一个数据库[TableBackup]。

2)要备份表,请为每个表执行此操作:

USE [TableBackup] GO IF OBJECT_ID('<<yourTable>>') IS NOT NULL DROP <<yourTable>>; SELECT * INTO <<yourTable>> FROM <<yourDB>>.dbo.<<yourTable>>; GO

3)要恢复表,请为每个表执行此操作:

USE [<<yourDB>>] GO TRUNCATE <<yourTable>>; INSERT INTO <<yourTable>> FROM [TableBackup].dbo.<<yourTable>>; GO

未经测试。 您可能必须为表上的外键和/或标识列调整此值。

So, if you only want to preserve that state of certain tables and then restore them later, this is what I would do:

1) Make another database [TableBackup].

2) To backup the tables, do this for each table:

USE [TableBackup] GO IF OBJECT_ID('<<yourTable>>') IS NOT NULL DROP <<yourTable>>; SELECT * INTO <<yourTable>> FROM <<yourDB>>.dbo.<<yourTable>>; GO

3) To restore the tables, do this for each table:

USE [<<yourDB>>] GO TRUNCATE <<yourTable>>; INSERT INTO <<yourTable>> FROM [TableBackup].dbo.<<yourTable>>; GO

Untested. You may have to adjust this for Foreign Keys and/or Identity columns on the tables.

更多推荐

本文发布于:2023-04-29 07:24:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1335959.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   Publish   script   huge   tables

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!