全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
触发器use EBuyif exists (select * from sys.all_objects where name=custDel and type=TR) -判断custDel存储过程是否存在,存在则删除它drop trigger custDelgocreate trigger custDel on customer -创建存储过程for delete -触发器类型asprint 客户记录被删除delete from customer where cusid=1201 -删除验证select * from customer -查询customer表sp_helptext custDel -查看存储过程use Study-创建新表create table major_stat(majorName varchar(50),toStu int,toCredit int)create trigger updateMajorStat -创建存储过程on studentfor insert,update,delete -触发器类型asbegindelete from major_statinsert into major_stat select majorName,count(*), sum(credit) from student s inner join major m on s.majorid=m.majorid group by majorNameendinsert into student values(071126,李静,2,男,1985-10-20,42,null)update student set credit=credit+2 where majorid=1delete from student where stuid=071126select * from studentselect * from major_stat-insert触发器use Studygoselect * from courseselect * from student_courseselect * from studentif exists(select name from sys.all_objects where name=insertScore and type=TR)drop trigger insertScoregocreate trigger insertScore on student_coursefor insertasif(select score from inserted)=60begindeclare stuid char(6),couid char(3),credit intselect stuid=stuid,couid=couid from insertedselect credit=couCredit from course where couid=couidupdate student set credit=credit+credit where stuid=stuidendinsert into student_course values(071001,C17,70)-update触发器if exists(select name from sys.all_objects where name=updateCouHour and type=TR)drop trigger insertScoregocreate trigger updateCouHouron coursefor updateasdeclare oldnum int,newnum intbeginselect oldnum=couHour from deletedselect newnum=couHour from insertedif newnumoldnum or newnum50beginprint 课时不能高于原课时数并且不能低于50rollback tranendendgoupdate course set couHour=couHour-2 where couid like A01-delete触发器create trigger delMajoron majorfor delete asif(select majorId from deleted)=1beginprint 不能删除计算专业rollback tranendgoalter table studentdrop constraint fk_student_majorgoselect * from majordelete from major where majorId=2select * into quit_stu from student where 1=2 -创建一个与student表结构相同的表quit_stucreate trigger delStuBackup -创建存储过程(把从student表删除的记录备份到quit_stu表)on studentfor deleteasinsert into quit_stu select * from deletedgodelete from student_course where stuid=071001delete from student where stuid=071001select * from student-instead ofuse Studyif exists(select name from sys.all_objects where name=delStuBackup and type=TR)drop trigger insertScoregocreate trigger delStuBackup -创建存储过程(把从student表删除的记录备份到quit_stu表)on studentinstead of deleteasdeclare stuid char(6)begin tryselect stuid=stuId from deleteddelete from student_course where stuId=stuiddelete from student where stuId=stuidinsert into quit_stu select * from deletedcommit tranprint 操作成功end trybegin catchrollback tranend catchgoset nocount on -不显示影响行数的消息godelete from student where stuId=071011select * from studentselect * from student_courseselect * from quit_stu-在视图上创建存储过程create table employee(empid char(5) primary key,name varchar(20),age int)create table jobs(id int identity(1,1) primary key,empid char(5),job varchar(30),salary money,foreign key(empid) references employee(empid)create view emp_job -创建视图asselect e.empid,name,age,job,salary from employee e inner join jobs j on e.empid=j.empidgoinsert into emp_job values(33012,jane,26,打字员,2000) -通过视图操作多个表提示有错误create trigger ins_emp_job -在视图上创建存储过程on emp_jobinstead of insertasinsert into employee select empid,name,age from insertedinsert into jobs select empid,job,salary from insertedgoinsert into emp_job values(33012,jane,26,打字员,2000) -创建完存储过程后,可以操作多个表select * from emp_job-触发器的查看、修改和删除sp_helptext ins_emp_job -查看触发器alter trigger delStuBackup -修改触发器on studentfor deleteasprint 触发器已经修改drop trigger delStuBackup -删除触发器alter table studentdisable trigg
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 供应链专员工作职责与物流优化方案
- 人力资源管理软件选型与系统实施方案
- 人事争议调解员调解委员会组建方案
- 2025年麻醉药品精神药品培训考核试题及答案
- 健康生活宝典均衡饮食与科学运动方案
- 企业培训师TTT训导师技能提升
- IT顾问IT咨询沟通技巧手册
- 健康饮食与运动结合科学减肥方法指南
- 2025年新媒体运营经理职业资格考核试题及答案解析
- 2025年环境保护政策与法律法规考试试题及答案
- 2025年青少年航天知识竞赛真题卷及答案
- 2025年大学《传播学-传播研究方法》考试备考题库及答案解析
- 2025年压疮护理指南
- 按摩行业服务礼仪培训
- 预应力管桩施工培训
- 黑龙江省哈尔滨市师范大学附中2025-2026学年高三上学期期中语文试题(含答案及解析)
- DB62T 3130-2017 公路沥青路面碎石封层设计与施工技术规范
- 饲料安全生产培训课件下载
- 2025年高中信息技术学业水平考试真题及答案
- 发展历程时间轴
- 旅行应急预案范文
评论
0/150
提交评论