触发器可以参考下面的,不过我感觉可以创建一个外键更好
create trigger tr_test_id
on test
after update
as
if not exists (select 1 from t1,inserted
where t1.name=inserted.name and t1.id=inserted.id)
begin
print '不允许修改!'
rollback transaction
end
两种方法:
一、
update tablea set fieldb=3 where exists(select * from tableb where tablea.fielda=tableb.fielda and tableb.fieldb=tablea.fieldb)
二、
UPDATE TABLEA SET FIELDB=3 FROM TABLEA,TABLEB WHERE TABLEA.FIELDA=TBLEB.FIELDA AND TABLEB.FIELDB=TABLEA.FIELDB