::----------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;
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;