alter trigger tri
on HR_PunchRecord
instead of insert
as
declare @FRegNo varchar(20)
declare @FEmpCode varchar(20)
declare @FPunchID varchar(20)
declare @FVerifyMode varchar(20)
declare @FDate varchar(20)
declare @FTime varchar(20)
declare @FPhoto varchar(20)
select @FRegNo=FRegNo,@FEmpCode=FEmpCode ,@FPunchID=FPunchID ,@FVerifyMode=FVerifyMode ,@FDate=FDate ,@FTime=FTime ,@FPhoto=FPhoto from inserted
if exists (select 1 from HR_PunchRecord where FRegNo=@FRegNo and FPunchID=@FPunchID and FDate=@FDate and FTime=@FTime)
begin
--print'存在'
rollback transaction
end
else
begin
insert into HR_PunchRecord ( HR_PunchRecord.FRegNo,HR_PunchRecord.FEmpCode,HR_PunchRecord.FPunchID,
HR_PunchRecord.FVerifyMode,HR_PunchRecord.FDate, HR_PunchRecord.FTime,
HR_PunchRecord.FPhoto, HR_PunchRecord.FIsNew)
values
(@FRegNo,@FEmpCode,@FPunchID,@FVerifyMode,@FDate,@FTime,@FPhoto,1)
end
FOR | AFTERAFTER 指定触发器仅在触发 SQL 语句中指定的所有操作都已成功执行时才被触发。所有的引用级联操作和约束检查也必须在激发此触发器之前成功完成。如果仅指定 FOR 关键字,则 AFTER 为默认值。不能对视图定义 AFTER 触发器。INSTEAD OF指定执行 DML 触发器而不是触发 SQL 语句,因此,其优先级高于触发语句的操作。如果仅指定 FOR 关键字,则 AFTER 为默认值。也就是说, FOR = AFTER。