Import first 1000 records into sql server from a c

2019-06-24 08:14发布

问题:

I need to import a csv file into sql server table, but i only want to import the first 1000 records of the csv file.

This is my sql code,

USE MyDB
BULK INSERT MyTable
FROM 'C:\Users\jasons\Desktop\Documents\MyFile.csv'
WITH(
FIRSTROW = 2,
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)

What do i need to add or how can i change my code to only import the first 1000 records.

回答1:

USE MyDB
BULK INSERT MyTable
FROM 'C:\Users\jasons\Desktop\Documents\MyFile.csv'
WITH(
FIRSTROW = 2,
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n',
LASTROW = 1001
)