What is bulk insert?

Source: Internet
Author: User
Tags bulk insert
Msdn explanation:

Import data files to database tables or views in the format specified by the user in SQL Server.

Syntax:
BULK INSERT    [ database_name . [ schema_name ] . | schema_name . ] [ table_name | view_name ]       FROM ‘data_file‘      [ WITH     (    [ [ , ] BATCHSIZE = batch_size ]    [ [ , ] CHECK_CONSTRAINTS ]    [ [ , ] CODEPAGE = { ‘ACP‘ | ‘OEM‘ | ‘RAW‘ | ‘code_page‘ } ]    [ [ , ] DATAFILETYPE =       { ‘char‘ | ‘native‘| ‘widechar‘ | ‘widenative‘ } ]    [ [ , ] FIELDTERMINATOR = ‘field_terminator‘ ]    [ [ , ] FIRSTROW = first_row ]    [ [ , ] FIRE_TRIGGERS ]    [ [ , ] FORMATFILE = ‘format_file_path‘ ]    [ [ , ] 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 ]    [ [ , ] ERRORFILE = ‘file_name‘ ]     )]
Simple application:

The table structure is as follows:

CREATE TABLE [dbo].[Types] (    [Id]        INT          IDENTITY (1, 1) NOT NULL,    [TypeName]  VARCHAR (50) DEFAULT (‘‘) NULL,    [TypeValue] INT          DEFAULT ((0)) NULL,    PRIMARY KEY CLUSTERED ([Id] ASC));

The content of the text file to be imported (D: \ a.txt) is as follows:

1,Add,12,Modify,23,Delete,4

Import command:

BULK INSERT dbo.Types FROM ‘D:a.txt‘ WITH(FIELDTERMINATOR=‘,‘)

Fieldterminator: delimiter between fields (default value: \ t tab );

Rowterminator: the delimiter between rows. The default value is \ r \ n ).

For other parameters, see the msdn annotation.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.