Простой вопрос про тригеры и ссылочную целостность
Вот код создания триггера:
create trigger tU_Work_Pressure on Work_Pressure for UPDATE as
/* ERwin Builtin Wed Dec 27 00:27:08 2006 */
/* UPDATE trigger on Work_Pressure */
begin
declare @numrows int,
@nullcnt int,
@validcnt int,
@insНачало_работы datetime,
@insPerson_No varchar(5),
@errno int,
@errmsg varchar(255)
select @numrows = @@rowcount
/* ERwin Builtin Wed Dec 27 00:27:08 2006 */
/* Person Имеет работы Work_Pressure ON CHILD UPDATE RESTRICT */
/* ERWIN_RELATION:PARENT_OWNER="", PARENT_TABLE="Person"
CHILD_OWNER="", CHILD_TABLE="Work_Pressure"
P2C_VERB_PHRASE="Имеет работы", C2P_VERB_PHRASE="Относится к",
FK_CONSTRAINT="Имеет_работы", FK_COLUMNS="Person_No" */
if
/* %ChildFK(" or",update) */
update(Person_No)
begin
select @nullcnt = 0
select @validcnt = count(*)
from inserted,Person
where
/* %JoinFKPK(inserted,Person) */
inserted.Person_No = Person.Person_No
/* %NotnullFK(inserted," is null","select @nullcnt = count(*) from inserted where"," and") */
if @validcnt + @nullcnt != @numrows
begin
select @errno = 30007,
@errmsg = 'Cannot UPDATE Work_Pressure because Person does not exist.'
goto error
end
end
/* ERwin Builtin Wed Dec 27 00:27:08 2006 */
return
error:
raiserror @errno @errmsg
rollback transaction
end
go