




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、(1) 设置一个触发器,该触发器仅允许“dbo”用户可以删除Employee表内数据,否则出错。create trigger EmploteeDelete on employeefor deleteas if exists (select * from deleted) begin if user!=dbo rollback end(2) 在OrderMaster表中创建触发器,插入数据时要先检查Employee表中是否存在同样值的业务员编号,如果不存在则不允许插入。create trigger insOrderMasteron OrderMasterfor insertasbegin if
2、exists (select * from inserted where salerNo not in (select employeeNo from Employee) rollback;end(3) 级联更新:当更新Customer表中customerNo列的值时,同时更新OrderMaster表中的customerNo列的值,并且一次只能更新一行。create trigger uptCustomer on Customerfor updateas declare oldCustomerNo char(9),newCustomerNo char(9) if (select count(*)
3、 from inserted)1 rollback else begin if update(customerNo) begin select oldCustomerNo=customerNo from deleted select newCustomerNo=customerNo from inserted update OrderMaster set customerNo=newCustomerNo where customerNo=oldCustomerNo end end(4) 对Product表写一个UPDATE触发器。当更新“主板”类的商品时,其单价不得高于原价格的10%creat
4、e trigger uptProduct on Productfor updateasbegin declare oldPrice numeric(7,2),newPrice numeric(7,2) if update(productPrice) begin declare myCur cursor for select ductPrice,ductPrice from inserted a,deleted b where ductNo=ductNo and ductClass=主板 open myCur fetch myCur into n
5、ewPrice,oldPrice while(fetch_status=0) begin if newPriceoldPrice+oldPrice*0.1 rollback fetch myCur into newPrice,oldPrice end close myCur deallocate myCur endend(5) 保证商品的销售单价必须在成本价的正负10%之内插入触发器create trigger insOrderDetail on OrderDetailfor insertasbegin declare productNo char(9),price numeric(7,2)
6、declare productPrice numeric(7,2),orderNo char(12) declare myCur cursor for select orderNo,ductNo,price,productPrice from Product a,inserted b where ductNo=ductNo open myCur fetch myCur into orderNo,productNo,price,productPrice while(fetch_status=0) begin if (priceproductPrice+product
7、Price*0.1 or priceproductPrice+productPrice*0.1 or newPriceproductPrice-productPrice*0.1) update OrderDetail set price=oldPrice where orderNo=orderNo and productNo=productNo fetch myCur into orderNo,productNo,newPrice,oldPrice,productPrice end close myCur deallocate myCur endend(6) 保证员工编码的第25位与员工的雇佣
8、日期的年份一致。插入触发器create trigger insEmplotee on employeefor insertasbegin declare employeeNo char(8),hireDate datetime declare subEmployeeNo char(4) declare myCur cursor for select employeeNo,hireDate from inserted open myCur fetch myCur into employeeNo,hireDate while(fetch_status=0) begin set subEmploye
9、eNo=substring(employeeNo,2,4) if (subEmployeeNo convert(char(4),hireDate,120) delete from Employee where employeeNo=employeeNo fetch myCur into employeeNo,hireDate end close myCur deallocate myCurend更新触发器create trigger uptEmplotee on employeefor updateasbegin declare employeeNo char(8),hireDate datetime declare subEmployeeNo char(4) if (update(employeeNo) or update(hireDate) begin declare myCur cursor for select employeeNo,hireDate from inserted open myCur fetch myCur into employeeNo,hireDate while(fetch_status=0) begin set subEmployeeNo=subs
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 中专升大专的试题及答案
- 2019-2025年军队文职人员招聘之军队文职教育学题库综合试卷A卷附答案
- 2019-2025年消防设施操作员之消防设备中级技能考前冲刺试卷A卷含答案
- 2022-2023学年广东省广州二中教育集团七年级(下)期中数学试卷(含答案)
- 遗产继承遗产分配争议解决合同(2篇)
- 采购与分包责任划分合同(2篇)
- 2023年云南公务员《行政职业能力测验》试题真题及答案
- 奢侈品知识培训课件图片
- 2025年法律知识竞赛抢答题库及答案(共70题)
- 急诊科急救知识培训课件
- 2025年中考百日誓师大会校长发言稿:激扬青春志 决胜中考时
- YY/T 1860.1-2024无源外科植入物植入物涂层第1部分:通用要求
- 中央2025年全国妇联所属在京事业单位招聘93人笔试历年参考题库附带答案详解
- 人教版高中物理选择性必修第二册电磁波的发射与接收课件
- 《建筑冷热源》全册配套最完整课件1
- 广州2025年广东广州市番禺区小谷围街道办事处下属事业单位招聘5人笔试历年参考题库附带答案详解
- 2025年春新人教版生物七年级下册全册教学课件
- 【物理】《跨学科实践:制作微型密度计》(教学设计)-2024-2025学年人教版(2024)初中物理八年级下册
- 2024年湖南高速铁路职业技术学院高职单招数学历年参考题库含答案解析
- 封条模板A4直接打印版
- 单细胞蛋白论文
评论
0/150
提交评论