全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
放心减肥网 提供实验27 查看、修改和删除触发器实验目的:掌握触发器的创建及其注意事项。实验课时:2课时实验方法:案例分析法实验内容:一、查看触发器 (1)sp_helptrigger 触发器名 查看触发器的名称,拥有者和五个布尔值 supdate,isdelete,isinsert,isafter,isinsteadof (2)sp_helptext 触发器名 查看文本信息 二、修改触发器重点演示如何设置触发器的无效和重新有效。 、无效: use northwind alter table 表名 disable trigger 触发器名 、重新有效: use northwind alter table 表名 enable trigger 触发器名 三、删除触发器 语法格式为drop trigger 触发器名【例1】在order_test表上建立一个插入触发器,在添加一个订单时,减少cust_test表的相应货物的记录的库存量。参考代码:use northwind go create trigger cust_orders_ins3 on order_test after insert as update cust_test set cstorage=cstorage-inserted.orders from cust_test,inserted where cust_test.customerid=inserted.customerid 【例2】在order_test表上建立一个插入触发器,规定订单日期(Odate)不能手工修改。 参考代码:use northwind go create trigger orderdateupdate on order_test after update as if update (odate) begin raiserror(Error,10,1) rollback transaction end【例3】要求订购的物品一定要在仓库中有的,并且数量足够。参考代码:use northwind go create trigger order_insert5 on order_test after insert as begin if(select count(*) from cust_test,inserted where cust_test.customerid=inserted.customerid)=0 begin print No entry in goods for your order rollback transaction end if(select cust_test.cstorage from cust_test,inserted where cust_test.customerid=inserted.customerid) (select inserted.orders from cust_test,inserted where cust_test.customerid=inserted.customerid) begin print No enough entry in goods for your order rollback transaction end end 作 业:在northwind 中order_test表上建立一个插入触发器,同时插入多行数据时,要求订购的物品一定要在仓库中有的。 参考代码:use northwind go create trigger order_insert6 on order_test after insert as if (select count(*) from cust_test,inserted where cust_test.customerid=inserted.customerid)rowcount -可以在触发器逻辑中使用 ROWCOUNT 函数以区分单行插入和多行插入。 begin delete order_test from order_test,inserted where order_test.orderid=inserted.orderid and inserted.customerid not in (select customerid from cust_test) end print rowcount 说 明 设置 SET ROWCOUNT 选项将使大多数 Transact-SQL 语句在已受指定数目的行影响后停止处理。这包括触发器和 INSERT、UPDATE 及 DELETE 等数
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 该制度的程序实现主要依赖于民事诉讼法中的行为保全制度
- 计生四项制度
- 供水稽查员春节假期安全告知书
- 2026福建省汽车工业集团有限公司招聘160人参考考试题库附答案解析
- 2026广东广州银行信用卡中心特殊资产部副职招聘1人参考考试试题附答案解析
- 2026天津南开区教育系统招聘(含高层次人才)170人备考考试试题附答案解析
- 2026广西柳州市第一批就业见习岗位招募128人参考考试试题附答案解析
- 2026年上半年黑龙江省体育局事业单位公开招聘工作人员13人备考考试试题附答案解析
- 2026年上半年黑龙江省事业单位公开招聘(4254人)备考考试题库附答案解析
- 2026公安部第三研究所招聘人民警察24人参考考试题库附答案解析
- 专题15平面解析几何(选择填空题)(第一部分)(解析版) - 大数据之十年高考真题(2014-2025)与优 质模拟题(新高考卷与全国理科卷)
- 茜草素的药代动力学和药效学研究
- T-CPQS C010-2024 鉴赏收藏用潮流玩偶及类似用途产品
- 林业管理制度
- HG/T 3811-2023 工业溴化物试验方法 (正式版)
- 2022年国际货代考试(海运)模拟试卷一
- 中小学建筑设计规范2022年
- 工程财务管理制度
- 天津大学研究生英语上机考试样题附答案
- 预制渡槽吊装施工专项方案
- 2吨每小时双级反渗透设备工艺流程介绍资料
评论
0/150
提交评论