Code
--当外修改TEST表中的F1字段时,同时根据条件修改F2字段
ALTER TRIGGER [dbo].[updatetest1] ON [dbo].[TEST]
FOR INSERT, UPDATE, DELETE
AS
begin
if update(F1)
declare
@fid int,
@f1 int
set @fid=(select fid from inserted) --获取被修改行ID
set @f1=(select f1 from inserted) --获取修改后内容
begin
if (select f1 from inserted) > 0
begin
update test set f2 = '5' where fid = @fid
end
if (select f1 from inserted) <= 0
begin
update test set f2 = '6' where fid = @fid
end
end
end
--当外修改TEST表中的F1字段时,同时根据条件修改F2字段
ALTER TRIGGER [dbo].[updatetest1] ON [dbo].[TEST]
FOR INSERT, UPDATE, DELETE
AS
begin
if update(F1)
declare
@fid int,
@f1 int
set @fid=(select fid from inserted) --获取被修改行ID
set @f1=(select f1 from inserted) --获取修改后内容
begin
if (select f1 from inserted) > 0
begin
update test set f2 = '5' where fid = @fid
end
if (select f1 from inserted) <= 0
begin
update test set f2 = '6' where fid = @fid
end
end
end
只是一个修改字段触发SQL语句的例子