sql - 最少记录的插入

标签 sql sql-server-2008 logging insert bulkinsert

我有一个 INSERT语句占用了大量的日志空间,以至于在语句完成之前硬盘驱动器实际上已被填满。

问题是,我真的不需要记录这个,因为它只是一个中间数据上传步骤。

为了论证,假设我有:

  • 表 A:初始上传表(使用 bcp 填充,因此没有日志问题)
  • 表 B:使用 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/

    相关文章:

    Mysql Mariadb 递归查询

    mysql - 在 mysql5 中创建更新操作触发器时出错?

    日期范围越小SQL查询时间越长?

    sql-server-2008 - SQL Server "."别名不工作

    xml - SQL Server FOR XML 封闭元素?

    mysql - 一张表多索引优化数据库性能

    c# - 开发环境设置 - 使用 C# Web 服务和 MS SQLServer 的 iphone iOS

    javascript - 如何停止 Node js-winston库中出现audit.json文件

    c# - 如何获取最后插入的记录

    python - 使用 Twisted 进行基本 HTTP 解析