::----------SQL觸發器-------------------------------------------------
1.刪除
CREATE TRIGGER [Delete_TopAlexa] ON [dbo].[tb_WebSite]
FOR DELETE
AS
BEGIN TRANSACTION
delete from tb_alexa where websiteid=(select websiteid from deleted)
delete from tb_top100 where websiteid=(select websiteid from deleted)
IF (@@ERROR <> 0) -- 如果有錯誤
BEGIN
ROLLBACK TRANSACTION -- 復原
END
COMMIT TRANSACTION -- 提交事務
2.更新
create trigger Test_OK
on ok
for update
as
if update(name)
begin
update sname set sname.s_name=ok.name from ok,sname
where sname.n_id=ok.n_id
end
::----------SQLite觸發器-------------------------------------------------
1.刪除
Create Trigger MAIN.[UserOK_DeleteOK] AFTER DELETE On [UserOK] FOR EACH ROW
begin
delete from userbak where uid=old.uid ;
end;
2.更新
Create Trigger MAIN.[UserOK_Update] AFTER UPDATE On [UserOK] FOR EACH ROW
begin
update userbak set username=new.username
where userbak.uid=old.uid ;
end;