简体   繁体   English

批量导入查询在SQL Server中不起作用

[英]Bulk Import query is not working in SQL server

i am trying to run this bulk import query and i keep getting the same error 'incorrect syntax near 'with'' The query is: 我正在尝试运行此批量导入查询,并且不断收到“与”附近的错误语法“语法不正确”,查询是:

BULK INSERT 
   [ Centra . [ dbo] .
   [ InfoHeader ] 
   FROM '‪C:\Share\092013-DB.txt' 
    [ WITH 
    ( 
   [ [ , ] BATCHSIZE = 10000000 ] 
   [ [ , ] CHECK_CONSTRAINTS ] 
   [ [ , ] CODEPAGE =  'OEM' ]
   [ [ , ] DATAFILETYPE =  'char']
   [ [ , ] FIELDTERMINATOR = '\t' ] 
   [ [ , ] FIRSTROW = 1 ] 
   [ [ , ] FIRE_TRIGGERS ] 
   [ [ , ] KEEPIDENTITY ] 
   [ [ , ] KEEPNULLS ] 
   [ [ , ] KILOBYTES_PER_BATCH = kilobytes_per_batch ] 
   [ [ , ] LASTROW = 0 ] 
   [ [ , ] MAXERRORS = 100 ] 
   [ [ , ] ROWS_PER_BATCH = rows_per_batch ] 
   [ [ , ] ROWTERMINATOR = '\r\n' ]  
   [ [ , ] ERRORFILE = 'C:\bulkimportlog.txt' ] 
   )] 

The [ WITH ... ] syntax means that WITH ... is optional . [ WITH ... ]语法表示WITH ...可选的

The square brackets is not part of the syntax, they're meant to signal that the enclosed portion of the syntax can be left out. 方括号不是语法的一部分,它们旨在表示可以省略语法的封闭部分。

You can see what all the symbols mean in the documentation here: Transact-SQL Syntax Conventions . 您可以在以下文档中查看所有符号的含义: Transact-SQL语法约定

Here's your edited SQL (untested): 这是您编辑的SQL(未经测试):

BULK INSERT Centra.dbo.InfoHeader
FROM '‪C:\Share\092013-DB.txt' 
WITH 
( 
    BATCHSIZE = 10000000,
    CHECK_CONSTRAINTS,
    CODEPAGE =  'OEM',
    DATAFILETYPE =  'char',
    FIELDTERMINATOR = '\t',
    FIRSTROW = 1,
    FIRE_TRIGGERS,
    KEEPIDENTITY,
    KEEPNULLS,
    KILOBYTES_PER_BATCH = kilobytes_per_batch, -- need number here
    LASTROW = 0,
    MAXERRORS = 100,
    ROWS_PER_BATCH = rows_per_batch,           -- and here
    ROWTERMINATOR = '\r\n',
    ERRORFILE = 'C:\bulkimportlog.txt'
)

Also, since most of these things are optional, you may not need nor want them all to be present in the statement, and if you leave them at the default values I would rather take them out and make the statement easier to read. 另外,由于这些内容大多数都是可选的,因此您可能不需要或不希望它们全部出现在语句中,如果将它们保留为默认值,我宁愿将其删除并使语句更易于阅读。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM