【发布时间】:2013-05-01 16:07:38
【问题描述】:
您可以在事务中放入的 INSERT 语句的数量是否有限制? 我收到传输错误,并且在运行语句的过程中连接断开。
我应该只填充一个临时表,然后运行一个 INSERT 语句吗?
在事务中插入 1000 多个中间的错误消息...
Msg 233, Level 20, State 0, Line 0
A transport-level error has occurred when receiving results from the server.
(provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.)
我在 SQL Server 2008 R2 10.50.4000.0 中针对本地 Windows 8 机器(Toshiba Satellite S955、x64 8GB RAM、Intel (R) Core(TM) i5-3317U CPU @ 1.70GHz 1.70 GHz)上的数据库运行脚本)
declare @currentDatabase nvarchar(255);
select @currentDatabase = DB_NAME();
if CHARINDEX('canada', @currentDatabase) = 0
begin
print 'Please run this script on the Canada server'
return
end
begin try
begin transaction
SET IDENTITY_INSERT company_name ON
insert into company_name (company_name_id, company_name, display_index, approved_by_administrator, requestor_id, modify_timestamp, active, create_timestamp) values (10000601010001, '6 Day Dental', 5868, 1, NULL, '2013-04-08 00:00:00.000', 1, '2013-04-08 00:00:00.000');
insert into company_name (company_name_id, company_name, display_index, approved_by_administrator, requestor_id, modify_timestamp, active, create_timestamp) values (10000601010002, '7-Eleven', 5869, 1, NULL, '2013-04-08 00:00:00.000', 1, '2013-04-08 00:00:00.000');
insert into company_name (company_name_id, company_name, display_index, approved_by_administrator, requestor_id, modify_timestamp, active, create_timestamp) values (10000601010003, 'AC Properties', 5870, 1, NULL, '2013-04-08 00:00:00.000', 1, '2013-04-08 00:00:00.000');
-- 1287 more INSERT statements...
SET IDENTITY_INSERT company_name OFF
commit
end try
begin catch
rollback
declare @Msg nvarchar(max)
select @Msg=Error_Message();
raiserror('Error Occured: %s', 20, 101,@Msg) with log
end catch
【问题讨论】:
-
你是如何执行脚本的?这个错误有already been asked about,但似乎每种情况都没有一个答案。为了回答您关于语句数量的问题,SQL Server 中有一个 maximum batch size,但默认情况下它是 256MB,因此这里似乎不太可能成为问题。
-
我只是在 SQL Server Management Studio (SQL Server 2008 R2 [10.50.400]) 中针对我的本地数据库运行脚本。
标签: sql-server tsql transactions sql-insert