SQL Server 2008 r2 のカーソルに次のコードがあります。
begin
if exists (select * from GestionIOF with (updlock,serializable) where Fecha
=@fechagestion and ID_Desc2 = @id_tipoalarmas and ID_Modulo = @id_modulo)
begin
update GestionIOF set Total = (Select Total from #Paso p where p.Fecha =
@fechagestion and p.Desc2 = @id_tipoalarmas and p.Modulo = @id_modulo),
Frecuencia = (Select Frecuencia from #Paso p where p.Fecha
= @fechagestion and p.Desc2 = @id_tipoalarmas
and p.Modulo = @id_modulo), Gestionado = 'False'
where GestionIOF.Fecha = @fechagestion and GestionIOF.ID_Desc2 =
@id_tipoalarmas and GestionIOF.ID_Modulo = @id_modulo
end
else
begin
INSERT INTO GestionIOF(ID_Area,ID_Controlador ,ID_Modulo
,ID_Desc2,ID_TipoEvento,Total,Frecuencia ,Fecha,Gestionado )
SELECT * FROM #Paso
end
主キーが存在するかどうかを確認し、存在しない場合は挿入します。しかし、次のエラーが発生します。
Mens 2627, Nivel 14, Estado 1, Procedimiento InsertarGestionEC_IOF, Línea 67 Infracción de la restriction PRIMARY KEY 'PK_GestionIOF'. 'dbo.GestionIOF' のオブジェクトを複製する必要はありません。
多分それはバグです。何か案は?