SQL,将数百万条记录从一个数据库移动到另一个数据库

标签 sql sql-server

我是一名 C# 开发人员,不太擅长 SQL。我在这里有一个简单的问题。我需要将超过 5000 万条记录从一个数据库移动到另一个数据库。我尝试使用 ms SQL 中的导入功能,但是由于日志已满而卡住了(我收到一条错误消息数据库“mydatabase”的事务日志因“LOG_BACKUP”已满)。数据库恢复模型设置为简单。我的 friend 说使用任务->导入数据导入数百万条记录会导致日志很大并告诉我使用循环而不是传输数据,有人知道如何以及为什么吗?提前致谢

最佳答案

如果您要移动整个数据库,请使用备份和恢复,这将是最快且最简单的。

http://technet.microsoft.com/en-us/library/ms187048.aspx

如果您只是移动单个表,请阅读并使用 BCP 命令行工具来处理这么多记录:

The bcp utility bulk copies data between an instance of Microsoft SQL Server and a data file in a user-specified format. The bcp utility can be used to import large numbers of new rows into SQL Server tables or to export data out of tables into data files. Except when used with the queryout option, the utility requires no knowledge of Transact-SQL. To import data into a table, you must either use a format file created for that table or understand the structure of the table and the types of data that are valid for its columns.

http://technet.microsoft.com/en-us/library/ms162802.aspx

关于SQL,将数百万条记录从一个数据库移动到另一个数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19578730/

相关文章:

sql - SQL中如何使用replace函数更新部分列数据?

sql - 为什么 sql case 不适用于 int 列的 null 条件

java - 找不到父 key ,我不知道为什么

sql - 使用 Clustered ColumnStore Index 插入唯一值

sql - 如何从查询中返回 SQL 数据类型?

sql - 如何配置 BizTalk WCF-SQL 适配器以从 SQL Server 2012 "always on"副本数据库获取数据?

mysql - 是否可以在 View 中使用对称键?

mysql - mysql 出错时的总和情况

php - 通过php、mysql脚本将大量记录(大约40,000条)插入到mysql中

mysql - 为总和(工作时间)< x 的用户选择最大日期