更新时间:2023-10-22 20:10:10
批量插入
充当一系列单独的 INSERT
语句,因此,如果
BULK INSERT
acts as a series of individual INSERT
statements and thus, if the job fails, it doesn't roll back all of the committed inserts.
但是可以将它放置在事务中,因此您可以执行以下操作:
It can, however, be placed within a transaction so you could do something like this:
BEGIN TRANSACTION
BEGIN TRY
BULK INSERT OurTable
FROM 'c:\OurTable.txt'
WITH (CODEPAGE = 'RAW', DATAFILETYPE = 'char', FIELDTERMINATOR = '\t',
ROWS_PER_BATCH = 10000, TABLOCK)
COMMIT TRANSACTION
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
END CATCH