BULK INSERT in SQL Server(T-SQL command)
Last Updated :
26 Jun, 2024
BULK INSERT in SQL Server(T-SQL command): In this article, we will cover bulk insert data from csv file using the T-SQL command in the SQL server and the way it is more useful and more convenient to perform such kind of operations. Let’s discuss it one by one.Â
Condition
Sometimes there is a scenario when we have to perform bulk insert data from .csv files into SQL Server database. We can use the GUI interface in SSMS(SQL Server Management Studio) to import data from Excel, CSV, etc files.
What if we have millions of data to be imported?
The above will be a time-consuming task so, now you will see how you can handle such kinds of operations.
SQL Server provides the BULK INSERT statement to perform large imports of data into SQL Server using T-SQL.

Note –Â Requires INSERT and ADMINISTER BULK OPERATIONS permissions.
Approach
Here, we will provide a faster alternative to the above via few lines of BULK INSERT in SQL Server T-SQL Command.Â
Genera Syntax for BULK INSERT in SQL Server(T-SQL command)
BULK INSERT <DATABASE NAME>.<SCHEMA NAME>.<TABLE_NAME>
FROM '<FILE_PATH>'
WITH
(
-- input file format options
[ [ , ] FORMAT = 'CSV' ]
[ [ , ] FIELDQUOTE = 'quote_characters']
[ [ , ] FORMATFILE = 'format_file_path' ]
[ [ , ] FIELDTERMINATOR = 'field_terminator' ]
[ [ , ] ROWTERMINATOR = 'row_terminator' ]
)]
)
The most commonly used input parameters are the following as follows.
- FIELDTERMINATOR –‘
‘field_terminator’ is used as a separator between fields. The default field terminator is \t (tab character).
Â
- ROWTERMINATOR –
‘row_terminator’ is used to specify the end of the row. The default row terminator is \r\n (newline character).Â
Importing CSV file into SQL table
Here, we will discuss importing CSV file into a table in SQL server. Consider the given below CSV file or you can use your own csv file to perform this operation. Let us try to import a csv file into our SQL table in SQL Server.

Now, let’s create the SQL table to store the above data.
Creating table
Here we will create the table schema as per csv file records.
USE [Test]--Database name
CREATE TABLE [dbo].[Employee](
[Emp ID] bigint primary key,
[First Name] [varchar](50) NULL,
[Last Name] [varchar](50) NULL,
[Salary] bigint,
[City] [varchar](50)
)
Bulk Inserting
Let’s now bulk insert the file into the Employee SQL table :
BULK INSERT [Test].[dbo].[Employee]
FROM 'C:\data\employee_data.csv'
WITH (FIRSTROW = 2,
FIELDTERMINATOR = ',',
ROWTERMINATOR='\n' );
Output –
After executing the above operation we can see the records have been inserted with few lines of code into the Employee table like below.

References :
To get more info on the input format options, visit https://docs.microsoft.com/en-us/sql/t-sql/statements/bulk-insert-transact-sql?view=sql-server-2017#input-file-format-options.
BULK INSERT in SQL Server(T-SQL command)- FAQs
How Do I Insert Data in Bulk?
To insert data in bulk in SQL, you can use a INSERT INTO statement with multiple rows:
INSERT INTO table_name (column1, column2)
VALUES
(value1, value2),
(value3, value4),
(value5, value6);
Why Use Bulk Inserts?
Efficiency: Reduces the number of database calls, improving performance.
Speed: Faster than inserting rows one at a time, especially for large datasets.
Resource Usage: Lowers network and server resource consumption.
What is Batch Insert in SQL?
A batch insert involves grouping multiple INSERT statements into a single batch to be executed together:
BEGIN;
INSERT INTO table_name (column1, column2) VALUES (value1, value2);
INSERT INTO table_name (column1, column2) VALUES (value3, value4);
INSERT INTO table_name (column1, column2) VALUES (value5, value6);
COMMIT;
What is Bulk Load in SQL?
Bulk load is a method to quickly import large amounts of data into a database from an external source, often using specialized commands or tools.
Example Command: In SQL Server, BULK INSERT is used:
BULK INSERT table_name
FROM ‘file_path’
WITH (
FIELDTERMINATOR = ‘,’,
ROWTERMINATOR = ‘\n’
);
Similar Reads
BULK INSERT in SQL Server(T-SQL command)
BULK INSERT in SQL Server(T-SQL command): In this article, we will cover bulk insert data from csv file using the T-SQL command in the SQL server and the way it is more useful and more convenient to perform such kind of operations. Let's discuss it one by one. ConditionSometimes there is a scenario
3 min read
Combine Rows into String in SQL Server
To combine rows into a string in SQL Server, use the SQL COALESCE() function or the SQL CONCAT() function. COALESCE() function in SQL is used to handle null values. It returns non-null values from a row, which can be concatenated into string. CONCAT() function in SQL is used to concatenate two or mo
2 min read
Insert Statement in MS SQL Server
The SQL Server INSERT statement is a fundamental command used to add new rows of data to a table. Whether we are inserting specific values, utilizing default values or copying data from another table. In this guide, weâll explore various ways to use the Insert statement in MS SQL Server with the hel
4 min read
Find Duplicates in MS SQL Server
Finding duplicate values in a database is a common task when managing data integrity. In SQL, several methods can be employed to identify and handle duplicate entries. In this article, We will explore two effective techniques for locating duplicates using SQL queries: the GROUP BY clause and the ROW
4 min read
Union and Union All in MS SQL Server
In MS SQL Server, the UNION and UNION ALL operators are used to combine the result sets of two or more SELECT statements into a single result set. This allows you to retrieve data from multiple tables or views and combine it into a single dataset. The primary difference between UNION and UNION ALL i
2 min read
TOP Clause in Microsoft SQL Server
TOP clause in Microsoft SQL Server fetches a limited number of rows from a database. The SELECT TOP clause is very useful when dealing with large databases. The TOP clause is useful for fetching the data records in larger datasets as it reduces the complexity. SyntaxTOP clause syntax in Microsoft SQ
2 min read
Swap Column Values in SQL Server
Introduction (Swap Column Values in SQL Server) : If you are a developer and have learned the programming languages, you might think that you will need a third variable or another temporary storage location to swap the values. Here, as you are a SQL Server DBA, you can simply swap them using a singl
1 min read
Difference between SQL and T-SQL
SQL (Structured Query Language) is the standard language for managing and manipulating relational databases, enabling operations like querying, updating, and deleting data. T-SQL (Transact-SQL), an extension of SQL developed by Microsoft, adds advanced features and procedural capabilities specifical
4 min read
CONCAT() function in SQL Server
CONCAT() : This function in SQL Server helps to concatenate two or more strings together. CONCAT() function can accept a minimum of 2 parameters and a maximum of 254 parameters. Syntax : CONCAT(string_1, string_2, .......string_n) Parameters : string_1, string_2, .......string_n - The given strings
2 min read
List All Databases in SQL Server
In SQL Server, databases are crucial for storing and managing data efficiently. Whether we are managing a large enterprise system or a small application, understanding how to list all the databases on our SQL Server is essential. In this article, we will write SQL queries that help us to retrieve al
3 min read