我有一个 INSERT
语句占用了大量的日志空间,以至于在语句完成之前硬盘驱动器实际上已被填满。
问题是,我真的不需要记录这个,因为它只是一个中间数据上传步骤。
为了论证,假设我有:
bcp
填充,因此没有日志问题)INSERT INTO B from A
填充有没有一种方法可以在 A 和 B 之间复制而不将任何内容写入日志?
附言我正在使用 SQL Server 2008 与 简单 恢复模型。
最佳答案
来自微软 MVP 路易斯戴维森:
There is no way to insert without logging at all. SELECT INTO is the best way to minimize logging in T-SQL, using SSIS you can do the same sort of light logging using Bulk Insert.
From your requirements, I would probably use SSIS, drop all constraints, especially unique and primary key ones, load the data in, add the constraints back. I load about 100GB in just over an hour like this, with fairly minimal overhead. I am using BULK LOGGED recovery model, which just logs the existence of new extents during the logging, and then you can remove them later.
The key is to start with barebones tables, and it just screams. Building the index once leaves you will no indexes to maintain, just the one index build per index.
如果您不想使用 SSIS,这一点仍然适用于删除所有约束并使用
BULK LOGGED
恢复模型。这大大减少了在 INSERT INTO
上完成的日志记录。声明,因此应该可以解决您的问题。http://msdn.microsoft.com/en-us/library/ms191244.aspx
关于sql - 最少记录的插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6266450/