BULK INSERT SQL query can be used to bulk insert data into a database table. The query imports data from a data file into a database table or view in the specified format. We can create and execute SQL query direct on SQL Server database.
Here is the BULK INSERT syntax:
- BULK INSERT
- { database_name.schema_name.table_or_view_name | schema_name.table_or_view_name | table_or_view_name }
- FROM 'data_file'
- [ WITH
- (
- [ [ , ] BATCHSIZE = batch_size ]
- [ [ , ] CHECK_CONSTRAINTS ]
- [ [ , ] CODEPAGE = { 'ACP' | 'OEM' | 'RAW' | 'code_page' } ]
- [ [ , ] DATAFILETYPE =
- { 'char' | 'native'| 'widechar' | 'widenative' } ]
- [ [ , ] DATASOURCE = 'data_source_name' ]
- [ [ , ] ERRORFILE = 'file_name' ]
- [ [ , ] ERRORFILE_DATA_SOURCE = 'data_source_name' ]
- [ [ , ] FIRSTROW = first_row ]
- [ [ , ] FIRE_TRIGGERS ]
- [ [ , ] FORMATFILE_DATASOURCE = 'data_source_name' ]
- [ [ , ] KEEPIDENTITY ]
- [ [ , ] KEEPNULLS ]
- [ [ , ] KILOBYTES_PER_BATCH = kilobytes_per_batch ]
- [ [ , ] LASTROW = last_row ]
- [ [ , ] MAXERRORS = max_errors ]
- [ [ , ] ORDER ( { column [ ASC | DESC ] } [ ,...n ] ) ]
- [ [ , ] ROWS_PER_BATCH = rows_per_batch ]
- [ [ , ] ROWTERMINATOR = 'row_terminator' ]
- [ [ , ] TABLOCK ]
- -- input file format options
- [ [ , ] FORMAT = 'CSV' ]
- [ [ , ] FIELDQUOTE = 'quote_characters']
- [ [ , ] FORMATFILE = 'format_file_path' ]
- [ [ , ] FIELDTERMINATOR = 'field_terminator' ]
- [ [ , ] ROWTERMINATOR = 'row_terminator' ]
- )]

Rasadul Alam RashedPosted Apr 17, 2013, 8:01 AM
Some times we need to insert massive data from CSV file to database. There are several ways to insert bulk data from a CSV file to a database. During this insertion time we need to consider the processing speed and time. Some common well known techniques are as follows. SQL BULK INSERT Query BCP or SqlBulkCopy library to insert bulk data using C# or VB SQL Server Integration Service (SSIS) Normal SQL command library in C# or VB A good example with source code :http://cybarlab.blogspot.com/2013/03/bulk-data-insertion-from-csv-to-sql.html Hope it will help you.
Kiran MaramPosted Apr 15, 2013, 7:47 AM
nice