The Bulk Insert in SQL Server (shortly called as BCP) will be very helpful to quickly transfer a large amount of data from Text File or CSV file to SQL Server Table or Views. In this article, we will show you, How to use BULK INSERT in SQL Server with an example.
BULK INSERT in SQL Server example
In this example, We will show you, How to transfer the data present in the text file to SQL table. We have a flat file called GEOGRAPHY.txt contains 1000000 Rows. Our task is to insert all the rows present in this text file using Bulk Insert statement.
Our SQL Server table is:
In order to transfer the data present in the text file or CSV file to SQL table, Please open your SQL Server Management Studio and write the following query
-- Example for BCP in SQL Server BULK INSERT [SQL Server Tutorials].[dbo].[DimGeography] FROM 'F:\MS BI\FILE EXAMPLES\Geography.txt' WITH ( DATAFILETYPE = 'char', FIELDTERMINATOR = ',', ROWTERMINATOR = '\n' );
TIP: If you want to send the data in multiple batches then use ROWS_PER_BATCH
Let us open the SQL Server Management Studio and check the destination table, whether we successfully copied the data from text file to SQL server or not.
Thank You for Visiting Our Blog