




已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
设计一个触发器,该触发器仅允许dbo用户可以删除employee3266表内数据,否则出错。create trigger employeedelete on employee3266for deleteas if exists(select *from deleted) begin if user!=dbo begin print 你无权删除! rollback end enddrop trigger employeedelete 测试:(以sa用户)delete from employee3266where employeeno=E2005001测试:(以其他用户)sp_addlogin wf,wf/*登录名 密码*/sp_adduser wf,wfgrant all privileges on employee3266 to wf;/*退出DBMS,重新以wf身份登入DBMS,执行删除操作*/delete from employee3266where employeeno=E2005001在ordermaster3266表中创建触发器,插入数据时要先检查employee3266表中是否存在和ordermaster3266表同样值的业务员编号,如果不存在则不允许插入。create trigger OrderMasterIns on OrderMaster3266for insertas if not exists(select b.saleNo from employee3266 a,inserted b,ordermaster3266 c where b.saleno=a.employeeNo) begin print 插入数据错误! rollback end检验:insert OrderMaster3266 values(200806135578,C20050001,E2009008,0.00,20080612,20080615,I000000010)请完成下面实验内容:(1) 创建触发器,该触发器仅允许“dbo”用户可以删除Employee表内数据。create trigger empdeton employee3266for deleteas if exists(select * from deleted) begin if user!=dbo rollback end测试一:exec sp_addlogin wfexec sp_adduser wfgrant all privileges on employee3266 to wf;delete from employee3266where employeeno=E2005001 测试二delete from employee3266where employeeno=E2005001(2) 创建触发器,保证Employee表中性别为”F”或”M”。 create trigger emp_sexon employee3266for insert,updateas if exists(select *from inserted where sex not in (F,M) rollback测试一:update employee3266 set sex=Gfrom employee3266where employeeno=E2005005测试二:update employee3266 set sex=Ffrom employee3266where employeeno=E2005005(3) 创建触发器,要求当修改Employee表的员工生日或雇佣日期时必须保证出生日期在雇佣日期之前,且年龄不小于岁,雇佣日期与出生日期必须间隔在年之上。create trigger employupton employee3266for updateas if update(birthday) or update(hiredate) begin declare birthday datetime,hiredate datetime select birthday=birthday,hiredate=hiredate from deleted if year(getdate()-year(birthday)25 rollback else if year(hiredate)-year(birthday)1 begin print 此删除操作可能会删除多条人事表数据! rollback transaction end else begin update ordermaster3266 set customerno=inserted.customerno from deleted,inserted where ordermaster3266.customerno=deleted.customerno endendalter table OrderMaster3266 drop constraint OrderMaster3266FK1update employee2689set employeeNo2689=C20080002where employeeNo2689=C20050001(5) 创建触发器,当业务员总销售业绩超过100000元时,其薪水自动增加20%,当业务员总销售业绩超过50000元低于100000时,其薪水自动增加10%,当业务员总销售业绩低于10000时,其薪水自动减少10%。create trigger salaryupton employee3266for updateas begin declare totsum numeric(9,2),employeeno char(8) declare emp_cur cursor for select saleno,sum(ordersum) from ordermaster3266 group by saleno open emp_cur fetch emp_cur into employeeno,totsum while(fetch_status=0) begin if totsum10000 begin update employee3266 set salary=b.salary*1.2 from employee3266 a,deleted b where a.employeeno=b.employeeno and a.employeeno=employeeno end else if totsum5000 begin update employee3266 set salary=b.salary*1.1 from employee3266 a,deleted b where a.employeeno=b.employeeno and a.employeeno=employeeno end else if totsummonth(b.hiredate)+3)or(year(getdate()=year(b.hiredate)+1 and month(getdate()3-12+month(b.hiredate)and
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025贵州六盘水市六枝特区黔发城市运营(集团)有限责任公司招聘笔试历年参考题库附带答案详解
- 2025福建福州市土地房屋开发总公司聘用人员招聘1人笔试历年参考题库附带答案详解
- 2025福建省福鼎市公共交通有限公司招聘驾驶员和广告部人员拟聘用笔试历年参考题库附带答案详解
- 2025福建漳龙集团有限公司招聘6人笔试历年参考题库附带答案详解
- 2025春季内蒙古建投国电准格尔旗能源有限公司校园招聘模拟试卷及一套答案详解
- 2025福建建工集团有限责任公司校园招聘51人笔试历年参考题库附带答案详解
- 2025安顺市参加“第十三届贵州人才博览会”引才1453人模拟试卷(含答案详解)
- 2025广东省风力发电有限公司山西分公司招聘笔试历年参考题库附带答案详解
- 2025年市场化选聘宁德市金禾房地产有限公司副总经理笔试历年参考题库附带答案详解
- 2025广东深圳市龙岗区园山街道招聘聘员12人模拟试卷附答案详解
- 韩语专业教育与职场应用能力培养融合研究
- 农机推广课件
- 小儿泌尿系感染的护理
- 水电站工程碾压混凝土大坝施工方案
- 2024年大学生入党积极分子培训班考试试题及答案
- 科研项目绩效管理办法
- 安全生产 技术规范
- 2025年 山东中烟工业有限责任公司招聘考试笔试试卷附答案
- 鱼苗配送服务方案(3篇)
- 产品可追溯管理制度
- 2025高考志愿第五轮学科评估(部分)+第四轮学科评估结果Excel表格
评论
0/150
提交评论