Skip to main content

SQL Query to Load Flat File Data into SQL SERVER Database: Using Bulk Insert

Hi Everyone,

We in general use SSIS to load Flat file Data to SQL Server DB. But this can be achieved even by using T-SQL Command.

Bulk Insert is a command used to import Text File data into SQL Server DB.

For Example, Say I'm having a flat File called Source on my desktop.

My Text File looks like :



Now To load this data into my SQL Server DB, Let me create a table in SQL Server.


Use Test
Go

Create Table Management (ID INT , Name Varchar(100), Designation Varchar(100))
Go


Now Below is the Query to load the Flat File Data into SQL Server  using Bulk Insert:

Bulk Insert
Management
From 'C:\Users\dhinakaran\Desktop\Source.txt'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)



This will insert all the data into my SQL Server DB.

Find complete Result in below snippet:



We can also get many more options other than FieldTerminator and RowTerminator. We can use them as per our requirement. You can refer them in Microsoft site Here.









Comments