积极答复者
BULK INSERT question

问题
-
I have a question about whether BULK INSERT handle a file as a transcation, from MSDN i found this:
BATCHSIZE =batch_size
Specifies the number of rows in a batch. Each batch is copied to the server as one transaction. If this fails, SQL Server commits or rolls back the transaction for every batch. By default, all data in the specified data file is one batch. For information about performance considerations, see "Remarks," later in this topic.
http://msdn.microsoft.com/en-us/library/ms188365(v=sql.105).aspx
It seems if we not indicate BATCHSIZE parameter, the whole process should be taken as a transcation, if one row failed, then the whole process should roll back.
Then i did a testing:
text file data:
"John","Smith","bill@smith.com"
"Sara","Parker","sara@parker.com"
"Kelly","Reynold","kelly@reynold.com"
create a table:
CREATE TABLE [dbo].[Person](
[FirstNmae] [varchar](50) NULL,
[LastName] [varchar](50) NULL,
[EmailAddress] [varchar](16) NULL
) ON [PRIMARY]
use bulk insert deal with data:
BULK INSERT Person FROM 'D:\test.txt' WITH (FIELDTERMINATOR = '","')
BULK INSERT Person FROM 'D:\test.txt' WITH (FIELDTERMINATOR = '","',BATCHSIZE =10000)
error:
Msg 4863, Level 16, State 1, Line 2
Bulk load data conversion error (truncation) for row 3, column 3 (EmailAddress).
Two rows successed, one row failed. It is not taken as a whole transcation process. Please advise. Thansk!
答案
-
- 已标记为答案 KevinLiu328 2012年9月21日 5:10
-
如楼上的链接所示(不是标记为答复的那个),MAXERRORS 的缘故,这个默认为10,你的文件中只有一条记录不合法,所以只会有1次错误,在欢歌的范围内
- 已标记为答案 Molly Chen_Moderator 2012年9月24日 6:59
全部回复
-
对的,我知道是这个问题。其实我做这个数据测试的目的是想知道BULK INSERT处理一个文件的过程是一个Transcation还是每一条记录当做一个Transcation.根据MSDN上边,我觉得应该是整个文件当做一个Transcation,那么这样的话应该都不会成功才对。但是我测试下来的结果是两条成功一条失败。所以想确定一下是不是我理解MSDN错误。
谢谢!
- 已编辑 KevinLiu328 2012年9月21日 3:43 更新
-
- 已标记为答案 KevinLiu328 2012年9月21日 5:10
-
如楼上的链接所示(不是标记为答复的那个),MAXERRORS 的缘故,这个默认为10,你的文件中只有一条记录不合法,所以只会有1次错误,在欢歌的范围内
- 已标记为答案 Molly Chen_Moderator 2012年9月24日 6:59