加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Sqlite 创建触发器

发布时间:2020-12-12 20:39:28 所属栏目:百科 来源:网络整理
导读:--创建班级表 create table class ( id integer primary key autoincrement,--班级编号 className nvarchar(50) --班级名称 ); --创建学生表 create table student ( id integer primary key autoincrement,--编号 stuName nvarchar(20),--学生名称 stuSex bi
--创建班级表 create table class ( id integer primary key autoincrement,--班级编号 className nvarchar(50) --班级名称 ); --创建学生表 create table student ( id integer primary key autoincrement,--编号 stuName nvarchar(20),--学生名称 stuSex bit,--性别 stuAge integer,--年龄 classId --班级编号 ); --创建插入触发器 (创建学生时要触发插入触发器去判断是否存在该班级,存在插入成功,反之插入失败) create trigger fk_Insert before insert on student for each row begin select raise(rollback,'还没有该班级') where (select id from class where id = new.classId ) is null; end; --创建更新触发器 (更新学生时要触发更新触发器去判断是否存在更新班级,存在更新成功,反之更新失败) create trigger fk_Update before update on student for each row begin select raise(rollback,'还没有该班级') where (select id from class where id = new.classId)is null; end; --创建删除触发器 (删除班级时,首先根据班级编号删除该班级学生) create trigger fk_Delete before delete on class for each row begin delete from student where classId = old.classId; end ; insert into class(className) values('s1t64'); insert into student(stuName,stuSex,stuAge,classId)values('zhangsan',1,23,1); update student set stuName='lishi',classId=1 where id = 1; select * from class ; select * from student limit 0,100 ; -- 分页查询从索引0开始查找,100条数据

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读