Now that I execute the trigger, it does not allow me to insert. I get the following:
Msg 544, Level 16, State 1, Procedure TR_TB_DISTRITO_INS, Line 5 [Batch Start Line 28] Can not insert explicit value for identity column in table 'TB_DISTRITO_AUDITORIA' when IDENTITY_INSERT is set to OFF.
This is my TB_AUDITORIA for the district table:
Create table [TB_DISTRITO_AUDITORIA]
(
[COD_DIS] Integer Identity(101,1) NOT NULL,
[NOM_DIS] Varchar(30) NOT NULL,
[FECHA_ACCION] DateTime,
[ACCION] varchar(20)
)
alter table [TB_DISTRITO_AUDITORIA]
alter column [COD_DIS] INTEGER NOT null
go
This is my audit trigger for insert:
create trigger [TR_TB_DISTRITO_INS]
on [TB_DISTRITO]
for insert
as
insert into [TB_DISTRITO_AUDITORIA]
(COD_DIS,NOM_DIS,FECHA_ACCION,ACCION)
select COD_DIS,NOM_DIS,GETDATE(),'INSERTADO'
from inserted
go
And this is my TB_DISTRITO
Create table [TB_DISTRITO] (
[COD_DIS] Integer Identity(101,1) NOT NULL,
[NOM_DIS] Varchar(30) NOT NULL,
Primary Key ([COD_DIS])
)
go
I appreciate the help in advance.