SQL Server: Bulk Insert into table with computed column

calculated-columns sql sqlbulkcopy sql-server


I try to insert data from a textfile into a SQL Server 2016 table with a computed column with bcp.

My bcp command:

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

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">
  <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"/>
  <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"/>

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". Ü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. BCP copy in failed

And in English

INSERT failed because the following SET options have incorrect settings: "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

11/22/2017 4:24:00 PM

Popular Answer

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!

11/23/2017 8:43:42 AM

Related Questions

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow