Sunday, 9 July 2017

Unknown

Import Data from a Text or CSV file into SQL Server

This is very useful SQL Query for import Data from a Text or CSV files into SQL Server.
You can easily achieve this thing by following below steps.

1. First of all, you need to create a particular table in which you want to import CSV file.  
USE Sample
GO
CREATE TABLE Employee
(Id INT,
FirstName VARCHAR(40),
LastName VARCHAR(40),
Designation VARCHAR(40),
BirthDate SMALLDATETIME)
GO
2. My Source Data in CSV file looks as per below and I have created it in C:\Employee (CSV).




3. Use below script to import CSV Data into SQL Employee Table.

BULK
INSERT Employee
FROM 'c:\Employee (CSV).txt'
WITH
(
FIELDTERMINATOR = ',',  --CSV field delimiter
ROWTERMINATOR = '\n' ,   --Use to shift the control to next row
TABLOCK
)
GO
After Executing above script:


Please let me know any update in above script.
Thank you.

Unknown

About Unknown -

Subscribe to this Blog via Email :