我使用 EF Core 2.2 创建了一个表格,并使用 bcp %database%.MyTable out MyTable.dmp -n -T -S %sqlserver%
导出。
当我使用 bcp %database%.MyTable in MyTable.dmp -n -T -S %sqlserver%
导入时,出现以下错误:
SQLState = 37000, NativeError = 1934
Error = [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]INSERT failed because the following SET options have incorrect settings: 'QUOTED_IDENTIFIER'. Verify that 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 index operations.
该表是使用
QUOTED_IDENTIFIER = ON
创建的,并且不包含任何计算列:SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [MyTable](
[Id] [bigint] IDENTITY(1,1) NOT NULL,
[OwnerLoginId] [bigint] NOT NULL,
[RowVersion] [timestamp] NULL,
[CreatedAt] [datetime2](7) NOT NULL,
[DataId] [bigint] NOT NULL,
[SomeString] [nvarchar](30) NOT NULL,
[AnotherString] [nvarchar](30) NULL,
CONSTRAINT [PK_MyTable] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [MyTable] WITH CHECK ADD CONSTRAINT [FK_MyTable_SomeOtherTable_DataId_SomeString] FOREIGN KEY([DataId], [SomeString])
REFERENCES [SomeOtherTable] ([DataId], [SomeString])
GO
ALTER TABLE [MyTable] CHECK CONSTRAINT [FK_MyTable_SomeOtherTable_DataId_SomeString]
GO
ALTER TABLE [MyTable] WITH CHECK ADD CONSTRAINT [FK_MyTable_DataTable_DataId] FOREIGN KEY([DataId])
REFERENCES [DataTable] ([Id])
GO
ALTER TABLE [MyTable] CHECK CONSTRAINT [FK_MyTable_DataTable_DataId]
GO
SET QUOTED_IDENTIFIER
是一个连接属性。听起来你的连接默认使用了SET QUOTED_IDENTIFIER OFF
。尝试添加-q
开关。 - Thom Abcp [My.Database].[MySchema].[MyTable] in MyTable.dmp -q -n -T -S(localdb)\ MSSQLLocalDB
中,我收到了“需要有效的表名以供选项使用。”的错误提示。我尝试过多种不同方式来输入表/数据库/模式名称(包括方括号和无方括号),但问题依然存在。此为bcp版本14。 - gumo-q
和数据库名称不符合常规标识符命名的组合是问题所在。我很快会发布答案。 - Dan Guzman