将大量记录插入 SQL 服务器
Inserting large number of records into SQL Server
我有大量记录必须插入到 SQL 服务器数据库中。必须插入大约 100 万条记录。
我通过 运行 宁这个简单的 bat 脚本来做到这一点:
ECHO %TIME%
sqlcmd -S "SQLSERVER" -i "C:\Users\name\Desktop\OutPut\Result
tblAccount.sql"
ECHO %TIME%
Pause
但是一旦我 运行 脚本我得到以下错误:
some part of your SQL statement is nested too deeply. Rewrite the query or break it up into smaller queries
插入那么多记录有什么解决办法吗?
我有 SQL Server 2014 开发版。
通过添加查询 I'm 运行ning
来编辑问题
IF NOT EXISTS (SELECT * FROM [dbo].[tblAccount]
WHERE [AccountID] = 117242
AND [TimeStamp] = CAST(N'2013-01-16 05:53:50.490' AS DateTime))
BEGIN
INSERT INTO [dbo].[tblAccount] ([AccountID], [Name], [Comment],[IsMachine],
[UserID], [Prefix], [Action], [Initials],
[Name], [TimeStamp], [Reason], [Iscal])
VALUES (117242, 'blabla', 'The users project)', 1,
'val', 39, 'val', 'blabla',
'blabla', CAST(N'2013-01-16 05:53:50.490' AS DateTime), 'NORMAL', '0')
END
根据此连接项,这似乎与 2012 年(已在 SP2 中修复)和 2014 年(已在 SP1 中修复)中的错误有关,
https://connect.microsoft.com/sqlserver/feedback/details/805659/sql-statement-is-nested-too-deeply -
我有大量记录必须插入到 SQL 服务器数据库中。必须插入大约 100 万条记录。
我通过 运行 宁这个简单的 bat 脚本来做到这一点:
ECHO %TIME%
sqlcmd -S "SQLSERVER" -i "C:\Users\name\Desktop\OutPut\Result
tblAccount.sql"
ECHO %TIME%
Pause
但是一旦我 运行 脚本我得到以下错误:
some part of your SQL statement is nested too deeply. Rewrite the query or break it up into smaller queries
插入那么多记录有什么解决办法吗?
我有 SQL Server 2014 开发版。
通过添加查询 I'm 运行ning
来编辑问题IF NOT EXISTS (SELECT * FROM [dbo].[tblAccount]
WHERE [AccountID] = 117242
AND [TimeStamp] = CAST(N'2013-01-16 05:53:50.490' AS DateTime))
BEGIN
INSERT INTO [dbo].[tblAccount] ([AccountID], [Name], [Comment],[IsMachine],
[UserID], [Prefix], [Action], [Initials],
[Name], [TimeStamp], [Reason], [Iscal])
VALUES (117242, 'blabla', 'The users project)', 1,
'val', 39, 'val', 'blabla',
'blabla', CAST(N'2013-01-16 05:53:50.490' AS DateTime), 'NORMAL', '0')
END
根据此连接项,这似乎与 2012 年(已在 SP2 中修复)和 2014 年(已在 SP1 中修复)中的错误有关, https://connect.microsoft.com/sqlserver/feedback/details/805659/sql-statement-is-nested-too-deeply -