我正在开发一个存储过程以将条目批量添加到表中。
这是我到目前为止所得到的:
use [DebugDatabase]
go
set ansi_nulls on
go
set quoted_identifier on
go
create procedure [dbo].[AddMultipleErrors]
@errors ErrorTableType readonly
as
declare @toInsert ErrorTableType
begin
insert into @toInsert select * from @errors
insert into [dbo].[Error] (ErrorMessage, FileId) select ErrorMessage, FileId from @toInsert
end
go
我收到消息“只有在使用列列表并且 IDENTITY_INSERT 为 ON 时,才能指定表 '@toInsert' 中标识列的显式值。”
我尝试在“declare”语句之后添加“set identity_insert @toInsert on”行,但出现“语法错误”错误。我已经尝试将它移动到其他几个位置,结果相同。
现在,我做了一些研究,看起来我实际上并不想将“identity_insert”设置为 on,因为它会要求我指定一个 id 而不是让表自动生成一个,这就是我确实想。
假设,我需要做的就是在插入调用中指定表中的每个单独的列,省略 id 值,并且一切都应该匹配得很好。但是,除非我弄错了,程序已经这样设置了,但它仍然不喜欢它。
有什么我可能会丢失的吗?