Bulk Insert Syntax

BULK INSERT Imports a data file into a database table or view in a user-specified format.

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‘ ]
    )] 

Critical Arguments

‘data_file ‘ 

Is the full path of the data file that contains data to import into the specified table or view. BULK INSERT can import data from a disk (including network, floppy disk, hard disk, and so on).

data_file must specify a valid path from the server on which SQL Server is running. If data_file is a remote file, specify the Universal Naming Convention (UNC) name. A UNC name has the form \\Systemname\ShareName\Path\FileName.

For example, \\SystemX\DiskZ\Sales\update.txt.

BATCHSIZE =batch_size  

Specifies the number of rows in a batch. Each batch is copied to the server as one transaction. If this fails, SQL Server commits or rolls back the transaction for every batch. By default, all data in the specified data file is one batch. For information about performance considerations, see "Remarks," later in this topic.

CHECK_CONSTRAINTS  

Specifies that all constraints on the target table or view must be checked during the bulk-import operation. Without the CHECK_CONSTRAINTS option, any CHECK and FOREIGN KEY constraints are ignored, and after the operation, the constraint on the table is marked as not-trusted.

UNIQUE and PRIMARY KEY constraints are always enforced. When importing into a character column that is defined with a NOT NULL constraint, BULK INSERT inserts a blank string when there is no value in the text file.

At some point, you must examine the constraints on the whole table. If the table was non-empty before the bulk-import operation, the cost of revalidating the constraint may exceed the cost of applying CHECK constraints to the incremental data.

A situation in which you might want constraints disabled (the default behavior) is if the input data contains rows that violate constraints. With CHECK constraints disabled, you can import the data and then use Transact-SQL statements to remove the invalid data.

KEEPIDENTITY  

Specifies that identity value or values in the imported data file are to be used for the identity column. If KEEPIDENTITY is not specified, the identity values for this column are verified but not imported and SQL Server automatically assigns unique values based on the seed and increment values specified during table creation. If the data file does not contain values for the identity column in the table or view, use a format file to specify that the identity column in the table or view is to be skipped when importing data; SQL Server automatically assigns unique values for the column. For more information, see DBCC CHECKIDENT (Transact-SQL).

For more information, see about keeping identify values see Keep Identity Values When Bulk Importing Data (SQL Server).

KEEPNULLS   

Specifies that empty columns should retain a null value during the bulk-import operation, instead of having any default values for the columns inserted. For more information, see Keep Nulls or Use Default Values During Bulk Import (SQL Server).

Performance Considerations   

If the number of pages to be flushed in a single batch exceeds an internal threshold, a full scan of the buffer pool might occur to identify which pages to flush when the batch commits. This full scan can hurt bulk-import performance. A likely case of exceeding the internal threshold occurs when a large buffer pool is combined with a slow I/O subsystem. To avoid buffer overflows on large machines, either do not use the TABLOCK hint (which will remove the bulk optimizations) or use a smaller batch size (which preserves the bulk optimizations).

Because computers vary, we recommend that you test various batch sizes with your data load to find out what works best for you.

参考文档:

MSDN BULK INSERT (Transact-SQL)

时间: 2024-10-06 23:12:31

Bulk Insert Syntax的相关文章

SQL SERVER 使用BULK Insert将txt文件中的数据批量插入表中(1)

1/首先建立数据表 CREATE TABLE BasicMsg( RecvTime FLOAT NOT NULL , --接收时间,不存在时间相同的数据 AA INT NOT NULL, --24位地址码 . FlightID Varchar(10) NULL, --航班号) 2/ 建立存储过程 USE DF17DataProIF EXISTS (SELECT * FROM SYS.PROCEDURES WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[BulkDataP

BULK INSERT如何将大量数据高效地导入SQL Server

转载自:http://database.51cto.com/art/201108/282631.htm BULK INSERT如何将大量数据高效地导入SQL Server 本文我们详细介绍了BULK INSERT将大量数据高效地导入SQL Server数据库的方法,希望本次的介绍能够对您有所帮助. AD:WOT2014课程推荐:实战MSA:用开源软件搭建微服务系统 在实际的工作需要中,我们有时候需将大量的数据导入到数据库中.这时候我们不得不考虑的就是效率问题.本文我们就介绍了一种将大量数据高效地

Bulk Insert:将文本数据(csv和txt)导入到数据库中

将文本数据导入到数据库中的方法有很多,将文本格式(csv和txt)导入到SQL Server中,bulk insert是最简单的实现方法 1,bulk insert命令,经过简化如下 BULK INSERT schema_name . table_name FROM 'data_file' WITH ( FIELDTERMINATOR = 'field_terminator', ROWTERMINATOR = 'row_terminator', DATAFILETYPE=‘WideChar’ )

Bulk Insert命令具体

BULK INSERT以用户指定的格式复制一个数据文件至数据库表或视图中. 语法: Sql代码 BULK INSERT [ [ 'database_name'.][ 'owner' ].]{ 'table_name' FROM 'data_file' } WITH  ( [ BATCHSIZE [ = batch_size ] ], [ CHECK_CONSTRAINTS ], [ CODEPAGE [ = 'ACP' | 'OEM' | 'RAW' | 'code_page' ] ], [ D

BULK INSERT导入数据库

BULK INSERT DBName.TableName FROM 'FileRoute' WITH ( Fieldterminator=',' ,rowterminator='\n' ,FirstRow=1) BULK INSERT导入数据库,布布扣,bubuko.com

Bulk Insert具体订单

BULK INSERT与用户指定的格式的数据文件复制到数据库表或视图. 语法: Sql代码 BULK INSERT [ [ 'database_name'.][ 'owner' ].]{ 'table_name' FROM 'data_file' } WITH  ( [ BATCHSIZE [ = batch_size ] ], [ CHECK_CONSTRAINTS ], [ CODEPAGE [ = 'ACP' | 'OEM' | 'RAW' | 'code_page' ] ], [ DAT

Bulk Insert 高效快速插入数据

BULK INSERT以用户指定的格式复制一个数据文件至数据库表或视图中. 语法: 1 BULK INSERT [ [ 'database_name'.][ 'owner' ].]{ 'table_name' FROM 'data_file' } 2 WITH ( 3 [ BATCHSIZE [ = batch_size ] ], 4 [ CHECK_CONSTRAINTS ], 5 [ CODEPAGE [ = 'ACP' | 'OEM' | 'RAW' | 'code_page' ] ],

高效的MySQL的批插入 BULK INSERT

原文:http://www.open-open.com/code/view/1453702496573 MySQL的批插入 BULK INSERT和load data的速度差不多,并且可靠. 语法如下 假设有表test (ID NUMBER,NAME VARCHAR(10)) insert into test values(1,'aa'),(2,'bb'),.....(100000,'bb'); 也就是每个记录间用逗号隔开,最后用分号结束,插入10万条记录只需不到10秒

SSIS常用的包—大量插入任务(Bulk Insert task)

大量插入任务允许像 BULK INSERT 语句或者bcp.exe 命令行工具一样 从 txt文件(也叫做平面文件)中插入数据.这个 task工具箱中的 Control Flow Items中,它不会产生数据流.这种 task的一个缺点是在插入的时候不允许任何形式的数据转换.同时,它可以以最快的速度向 SQL Server中写入大量的数据,不论数据量是的是小. 创建一个大量插入任务,然后设置它的属性,打开编辑页面(图 3-2).像大多数 task一样编辑页面可以命名,描述这个 task.注意命名