create trigger ... on ...
for insert,update,delete
as
if exists(select 1 from inserted) and not exists(select 1 from deleted)
begin
...此处写insert时的代码...
end
if exists(select 1 from inserted) and exists(select 1 from deleted)
begin
...此处写update时的代码...
end
if not exists(select 1 from inserted) and exists(select 1 from deleted)
begin
...此处写delete时的代码...
end
for insert,update,delete
as
if exists(select 1 from inserted) and not exists(select 1 from deleted)
begin
...此处写insert时的代码...
end
if exists(select 1 from inserted) and exists(select 1 from deleted)
begin
...此处写update时的代码...
end
if not exists(select 1 from inserted) and exists(select 1 from deleted)
begin
...此处写delete时的代码...
end
ON employee
FOR INSERT, UPDATE,DELETE
AS
...
建議樓主不要寫在一起。
UPDATE -- inserted(更改後的數據) ,deleted (更改前的數據)
DELETE --deleted