BCP可以直接从表到表复制数据吗?
我遇到了一种情况,需要将多个表从一个 SQL Server 数据库复制到另一个单独的 SQL Server 数据库。数据库位于同一实例上。我正在复制的表至少包含 450 万行,大小约为 40GB 以上。
我以前使用过 BCP,但对它不是很熟悉,并且无法找到任何有关是否可以使用 BCP 直接从表复制到表而不在其间写入文件的文档。
这可能吗?如果是这样,怎么办?
编辑:我们不使用直接插入的原因是因为我们服务器上的日志驱动器空间有限,在尝试插入时几乎立即消失。我们确实尝试过,但随着日志驱动器填满,查询速度很快就慢了下来。
I've got a situation where I need to copy several tables from one SQL Server DB to a separate SQL Server DB. The databases are both on the same instance. The tables I'm copying contain a minimum of 4.5 million rows and are about 40GB upwards in size.
I've used BCP before but am not hugely familiar with it and have been unable to find any documentation about whether or not you can use BCP to copy direct from table to table without writing to file in between.
Is this possible? If so, how?
EDIT: The reason we're not using a straightforward INSERT is because we have limited space on the log drive on the server, which disappears almost instantly when attempting to INSERT. We did try it but the query quickly slowed to snail's pace as the log drive filled up.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据我在表级备份的回答,
我正在使用bcp.exe 实现表级备份
导出:
导入:
如您所见,可以根据导出任何查询,因此您甚至可以用它进行增量备份。
from my answer at Table-level backup
I am using bcp.exe to achieve table-level backups
to export:
to import:
as you can see, you can export based on any query, so you can even do incremental backups with this.
BCP 用于转储到文件/从文件读取。使用 DTS/SSIS 从一个数据库复制到另一个数据库。
以下是 MSDN 上的 BCP 文档
BCP is for dumping to / reading from a file. Use DTS/SSIS to copy from one DB to another.
Here are the BCP docs at MSDN
SQL 导入/导出向导将完成这项工作...只需连接两次到同一数据库(源和目标)并将一个表复制到另一个表(空且已索引),您可能需要指示忽略自动数字 Id 键字段(如果存在)。这种方法适用于超过 1M+ 记录的表。
SQL Import/Export wizard will do the job ... just connect twice to same database (source and destination) and copy one table onto other (empty and indexed), you might want to instruct to ignore autonumeric Id key field if exists. This approach works for me with tables over 1M+ records.
TableDiff.exe 可能会执行您想要的操作
https://solutioncenter .apexsql.com/automatically-compare-and-synchronize-sql-server-data/
TableDiff.exe might do what you want
https://solutioncenter.apexsql.com/automatically-compare-and-synchronize-sql-server-data/