This article is half-done without your Comment! *** Please share your thoughts via Comment ***
In this post, I am sharing a demonstration of BULK INSERT for inserting data from flat file into the table of SQL Server.
As an ELT developer or database developer, this is a ubiquitous requirement to import external file data into the table of SQL Server.
Please check below demonstration and try it your self.
Create a sample table:
1 2 3 4 5 6 7 8 |
CREATE TABLE dbo.tbl_Employees ( empid int ,empname varchar(10) ,empgender varchar(6) ,empsalary int ) GO |
Add sample data in .csv file and save it:
Use BULK INSERT for inserting data into the table:
1 2 3 4 5 6 7 8 9 10 |
BULK INSERT dbo.tbl_Employees FROM 'D:\empdata.csv' WITH ( FIRSTROW = 2, FIELDTERMINATOR = ';', --delimiter ROWTERMINATOR = '\n', --For next row TABLOCK, CODEPAGE = 'ACP' ); |
1 |
SELECT *FROM dbo.tbl_Employees |
1 2 3 4 5 6 |
empid empname empgender empsalary ----------- ---------- --------- ----------- 1 anvesh male 150000 2 roy male 120000 3 jenny female 60000 4 nupur female 90000 |
Leave a Reply