[英]SQL Server: Bulk Insert into table with computed column
I try to insert data from a textfile into a SQL Server 2016 table with a computed column with bcp.我尝试将文本文件中的数据插入 SQL Server 2016 表中,并使用 bcp 计算列。
My bcp command:我的 bcp 命令:
bcp Test.dbo.myFirstImport IN D:\myFirstImport.txt -f D:\myFirstImport.xml –T
My table:我的表:
CREATE TABLE [dbo].[MyFirstImport](
[PersonID] [smallint] NULL,
[FirstName] [varchar](25) NULL,
[LastName] [varchar](30) NULL,
[BirthDate] [date] NOT NULL,
[YearMonthCom] AS (datepart(year,[BirthDate])*(100)+datepart(month,[BirthDate])) PERSISTED
) ON [PRIMARY]
My Data (tab separated):我的数据(制表符分隔):
1 Anthony Grosse 1980-02-23
2 Alica Fatnowna 1963-11-14
3 Stella Rosenhain 1992-03-02
My format file:我的格式文件:
<?xml version="1.0"?> <BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <RECORD> <FIELD ID="1" xsi:type="CharTerm" TERMINATOR="\\t" MAX_LENGTH="7"/> <FIELD ID="2" xsi:type="CharTerm" TERMINATOR="\\t" MAX_LENGTH="25" COLLATION="SQL_Latin1_General_CP1_CI_AS"/> <FIELD ID="3" xsi:type="CharTerm" TERMINATOR="\\t" MAX_LENGTH="30" COLLATION="SQL_Latin1_General_CP1_CI_AS"/> <FIELD ID="4" xsi:type="CharTerm" TERMINATOR="\\r\\n" MAX_LENGTH="11"/> <!-- <FIELD ID="4" xsi:type="CharTerm" TERMINATOR="\\t" MAX_LENGTH="11"/> <FIELD ID="5" xsi:type="CharTerm" TERMINATOR="\\r\\n" MAX_LENGTH="12"/> --> </RECORD> <ROW> <COLUMN SOURCE="1" NAME="PersonID" xsi:type="SQLSMALLINT"/> <COLUMN SOURCE="2" NAME="FirstName" xsi:type="SQLVARYCHAR"/> <COLUMN SOURCE="3" NAME="LastName" xsi:type="SQLVARYCHAR"/> <COLUMN SOURCE="4" NAME="BirthDate" xsi:type="SQLDATE"/> <!-- <COLUMN SOURCE="5" NAME="YearMonthCom" xsi:type="SQLINT"/> --> </ROW> </BCPFORMAT>
My error我的错误
SQLState = 37000, NativeError = 1934 Error = [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Fehler bei INSERT, da die folgenden SET-Optionen falsche Einstellungen aufweisen: "QUOTED_IDENTIFIER".
SQLState = 37000,NativeError = 1934 错误 = [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Fehler bei INSERT, da die folgenden SET-Optionen falsche Einstellungen aufweisen:“QUOTED_IDENTIFIER”。 Überprüfen Sie, ob die SET-Optionen für die Verwendung mit indizierte Sicht en und/oder Indizes für berechnete Spalten und/oder gefilterte Indizes und/oder Abfragebenachrichtigungen und/oder XML-Datentypmethoden und/oder Vorgänge für rä umliche Indizes richtig sind.
überprüfen Sie, ob die SET-Optionen für die Verwendung mit indizierte Sicht en und/oder Indizes für berechnete Spalten und/oder gefilterte Indizes und/oder Abfragebenachrichtigungen und/oder XML-Datentypmethogemändärl BCP copy in failed
BCP 复制失败
And in English和英文
INSERT failed because the following SET options have incorrect settings: "QUOTED_IDENTIFIER".
INSERT 失败,因为以下 SET 选项的设置不正确:“QUOTED_IDENTIFIER”。 Verify that the SET options are correct for use with indexed views and / or indexes on computed columns and / or filtered indexes and / or query notifications and / or XML data type methods and / or spatial indices operations
验证 SET 选项是否正确用于计算列上的索引视图和/或索引和/或过滤索引和/或查询通知和/或 XML 数据类型方法和/或空间索引操作
I created another table without that computed column and bcp worked, just to be sure it is an issue with the computed column.我创建了另一个没有该计算列的表,并且 bcp 可以工作,只是为了确定这是计算列的问题。 Then I recreated the table (with computed column) with QUOTED_IDENTIFIER set to ON - see Jacob's comment - and it still did not work.
然后我重新创建了表(带有计算列),并将 QUOTED_IDENTIFIER 设置为 ON - 请参阅 Jacob 的评论 - 但它仍然不起作用。 But when I started bcp with -q it worked.
但是当我用 -q 启动 bcp 时它起作用了。 So thank you, Jacob!
所以谢谢你,雅各布!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.