create table test (id int IDENTITY, amount int check(amount >=1000 and amount<=5000)); SELECT * FROM dbo.test /* 下面这个语句不检查约束: */ SET IDENTITY_INSERT dbo.test OFF bulk insert dbo.test from ‘f:\test.txt‘ with (fieldterminator=‘,‘, rowterminator=‘\n‘) /* 这个是启用约束的: */ bulk insert test from ‘f:\test.txt‘ with (fieldterminator=‘,‘, rowterminator=‘\n‘, check_constraints) select * from test /* 还可以使用FIRSTROW和LASTROW限制行数。如下COPY前三行: */ bulk insert test from ‘f:\test.txt‘ with (fieldterminator=‘,‘, rowterminator=‘\n‘, FIRSTROW =1, LASTROW=3) /* 使用ERRORFILE选项 错误处理,如下记录到F:\error.txt */ bulk insert test from ‘f:\test.txt‘ with (fieldterminator=‘,‘, rowterminator=‘\‘, FIRSTROW =1, LASTROW=3, ERRORFILE =‘F:\error.txt‘, check_constraints)
sql bulk insert
时间: 2024-10-11 09:45:36