The Bulk Insert in SQL Server (shortly called BCP) will be very helpful in quickly transferring a large amount of data from a Text File or CSV file to a Table or View.

BULK INSERT in SQL Server Example

In this SQL Server Bulk Insert example, we will show you how to transfer the data present in the text file to the table.

We have a flat file called GEOGRAPHY.txt containing 1000000 Rows. Our task is to insert all the rows present in this text file using the Bulk Insert statement.

Text File 1

Our SQL Server table is empty, as shown below:

Empty Table 2

In order to transfer the data present in the text file or CSV file to the table, First, Please open your Management Studio and write the following query.

BULK INSERT [DimGeography] 
      FROM 'F:\MS BI\FILE EXAMPLES\Geography.txt' 
       DATAFILETYPE    = 'char', 
       FIELDTERMINATOR = ',', 
       ROWTERMINATOR   = '\n' 
(1000000 row(s) affected)

If you want to send the data in multiple batches, then use ROWS_PER_BATCH

Let us open the Management Studio and check the destination table. We could successfully copy the data from a text file to the Server table or not use this Bulk insert.

SQL Server BULK INSERT Example 6
Categories SQL

Comments are closed.