大家好,我想创建触发器以在插入之前将插入表中的行与表进行比较我有一个名为“ cv_langues
”的表,有 2 列“ id_cv,id_langues
”这是我的触发器:
alter trigger insertion_cv_langue
on cv_langues
for insert
as
begin
declare @id_langue int,@id_cv int, @inserted_langue int,@inserted_cv int,@comp int
set @comp=0
declare cv_langues cursor
for select id_langue,id_cv from cv_langues
declare inserted_cv_langues cursor
for select id_langue,id_cv from inserted
open inserted_cv_langues
fetch inserted_cv_langue into @inserted_langue,@inserted_cv //1st line to compare
close inserted_cv_langue
open cv_langues
while @@fetch_status = 0
begin
fetch cv_langues_1 into @id_langue,@id_cv // multi lines from cv_langues
if @id_langue = @inserted_langue and @id_cv = @inserted_cv
begin
set @comp = @comp+1
end
end
if @comp =2
rollback
close cv_langues_1
end
deallocate inserted_cv_langue
deallocate cv_langues_1