SQL Server – Import CSV file to SQL table – Bulk-Insert

Here is an example –  Import CSV file to SQL table using Bulk-Insert

CSV file means  Comma Separated Values file.

USE testdb
GO

CREATE TABLE table1
(
    id INT,
    name VARCHAR(255),
    address VARCHAR(255)
)
GO

Create CSV file in Shared folder on any remote location with name csv.txt

Suppose location of the file is \\dcc-566\Share\CSV.txt

Content of CSV file as :

Now let‘s Import this CSV file into Table1.

BULK
INSERT table1
FROM '\\dcc-566\Share\CSV.txt'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO

 

5 comments