qt sqlite 触发器 使用

前端之家收集整理的这篇文章主要介绍了qt sqlite 触发器 使用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
首先看下基本的触发器的结构
:: -- --------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

说明: 关键字都用大写的蓝色字体标出, 斜体字代表用户字符串

triggername-------------触发器的名字

mainTableName------主表名

childTableName-------子表名

ctbid-------------------------子表的字段

mid--------------------------主表的比较字段


::----------sqlite触发器-------------------------------------------------
1.删除
CREATE TRIGGERtriggernameAFTERDELETEONmainTableNameFOREACHROW
BEGIN
DELETEFROMchildTableNameWHEREctbid=OLD.mid;
END;

2.更新
CREATE TRIGGERtriggernameAFTERUPDATEONmainTableName FOREACHROW
BEGIN
UPDATEchildTableNameSETctbid =NEW.mid
WHERE childTableName.ctbid= OLD.mid;
END;

原文链接:https://www.f2er.com/sqlite/202574.html

猜你在找的Sqlite相关文章