本文介绍了SQL Server:批量插入到带有计算列的表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试将文本文件中的数据插入带有bcp的带有计算列的SQL Server 2016表中。
I try to insert data from a textfile into a SQL Server 2016 table with a computed column with bcp.
我的bcp命令:
bcp Test.dbo.myFirstImport IN D:\myFirstImport.txt -f D:\myFirstImport.xml –T
我的桌子
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
我的格式文件:
<?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>
我的错误
并且用英语
推荐答案
我创建了另一个没有该计算列的表,并且bcp起作用了,只是为了确保它与计算列有关。
然后,我将QUOTED_IDENTIFIER设置为ON来重新创建表(带有计算列)-请参见Jacob的注释-仍然不起作用。
但是当我用-q启动bcp时,它起作用了。所以,谢谢你,雅各布!
I created another table without that computed column and bcp worked, just to be sure it is an issue with the computed column.Then I recreated the table (with computed column) with QUOTED_IDENTIFIER set to ON - see Jacob's comment - and it still did not work.But when I started bcp with -q it worked. So thank you, Jacob!
这篇关于SQL Server:批量插入到带有计算列的表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!