BULK INSERT in SQL Server

In SQL Server, bulk insert imports a data file in a user-specified format into a database table or view. We’ll be able to import CSV, TXT, DAT, and other files into SQL Server with this command. Before inserting data into a table, it must exist.

Example for TEXT file:

BULK INSERT tbVehicleDetails
FROM ‘C:\Users\User\Documents\VehicleDetails.txt’
WITH
(
FIELDTERMINATOR = ‘\t’,
ROWTERMINATOR = ‘\n’,
FIRSTROW=2
)
GO

Example for CSV file:

BULK INSERT dbo.Actors
FROM ‘C:\Users\User\Documents\VehicleDetails.csv’
WITH
(
FORMAT=’CSV’,
FIELDTERMINATOR = ‘\t’,
FIRSTROW=2
)
GO

Hope this helps.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s