存储过程,游标和触发器实例
自己写的存储过程与游标结合使用的实例,与大家分享,也供自己查阅,仅供参考:
--使用游标循环处理,删除重复的记录declare @UserID intdeclare @UserName varchar(32)declare @RealName varchar(32)declare @UnitFlag intdeclare @Email2 varchar(64)declare @Mobile varchar(64)declare @Start intdeclare @End intdeclare @Type varchar(16)declare @IsSubscribe bitdeclare curEmailTotalLib cursorfor (select UserID,UserName,RealName,UnitFlag,Email,Mobile,IsSubscribe from Task_IntermediateData)open curEmailTotalLib --打开游标fetch next from curEmailTotalLib into @UserID, @UserName, @RealName, @UnitFlag, @Email2, @Mobile, @IsSubscribewhile @@fetch_status = 0 --获取成功begin--在邮件系统总库中不存在此用户ID,不存在此邮箱,并且用户订阅过if not exists(select * from Task_EmailTotalLib where UserID = @UserID)and not exists(select * from Task_EmailTotalLib where Email = @Email2)and @IsSubscribe = 1beginset @Start = charindex('@', @Email2, 0)set @End = charindex('.', @Email2, @Start)if @Start != 0 and @End != 0begin--不是垃圾邮件if @Email2 is not null and ltrim(rtrim(@Email2)) <> ''beginif not exists(select * from Task_JunkEmail where Email = @Email2)beginbegin tryset @Type = substring(@Email2, @Start + 1, @End - @Start - 1)if @Type != 'qq' and @Type!='126' and @Type != '163' and @Type!='sina'and @Type !='sohu' and @Type != 'gmail' and @Type!='hotmail' and@Type != 'yahoo' and @Type != '139' and @Type != '263' and @Type !='yeah' and @Type != 'cnki'beginset @Type = 'extra'endinsert into Task_EmailTotalLib(UserID, UserName, RealName, Email, Mobile,Priority, MailType, LibType, FpIsSend, CpIsSend, UpIsSend, VpIsSend, WpIsSend,XpIsSend, YpIsSend, ZpIsSend, SendCount, SucCount, FailCount, CreditRate, IsJunkEmail,IsSubscribe, IsUsed, Memo) values(@UserID, @UserName, @RealName, @Email2, @Mobile,2, @Type, @UnitFlag, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, @IsSubscribe, 0, '')end trybegin catchprint '@Email2:'+@Email2+'charindex(''@'', @Email2, 0)'+charindex('@', @Email2, 0)+' @Start'+@Start+' @End'+@End+' @End - @Start - 1:'+@End - @Start - 1end catchendendendendfetch next from curEmailTotalLib into @UserID, @UserName, @RealName, @UnitFlag, @Email2, @Mobile, @IsSubscribeendclose curEmailTotalLib --关闭游标deallocate curEmailTotalLib --释放游标
触发器实例:插入数据时,触发器获取这条数据ID,自动修改,比程序处理更方便。
Create trigger tg_url_update on [dbo].UrlTotal for insert as
declare @getid int;
declare @url varchar(128);
set @getid=(select id from inserted);
set @url='Test.aspx?id='+cast(@getid as varchar(50))
update UrlTotal set url=@url where id=@getid
谢谢阅读~~
转载于:https://www.cnblogs.com/lonelyxmas/p/3587900.html
存储过程,游标和触发器实例相关推荐
- 数据库实验:数据库和表、查询、视图与安全性、存储过程及游标、触发器、综合实验-水果商店进阶
数据库实验:数据库和表.查询.视图与安全性.存储过程及游标.触发器.综合实验-水果商店进阶 实验一.数据库和表 源码1: 源码2: 小结 实验二.查询 源码 小结 实验三.视图.安全性 源码: 小结 ...
- 视图、存储过程、函数、游标、触发器使用
说明及使用: 视图.存储过程.函数.游标与触发器介绍_百度文库 一.视图注意:1.不能够在创建视图的查询语句中,使用order by排序语句 2.不能带参数 二.存储过程与函数: 1存储过程可以有多个 ...
- 【MySQL学习】使用视图、存储过程、游标和触发器
视图.储存过程.游标和触发器 视图 利用视图简化复杂的联结 用视图重新格式化检索出的数据 用视图过滤不想要的数据 使用视图与计算字段 更新视图 存储过程 为什么要使用存储过程 使用存储过程 执行存储过 ...
- Oracle学习2 视图 索引 sql编程 游标 存储过程 存储函数 触发器
---视图 ---视图的概念:视图就是提供一个查询的窗口,来操作数据库中的数据,不存储数据,数据在表中. ---一个由查询语句定义的虚拟表.---查询语句创建表 create table emp as ...
- Oracle就业课第六课之游标和触发器
oracle 游标和触发器 回顾 表空间 表空间:逻辑名词:表.视图.索引:拆分:段.区 .块(最小的存储单元) 物理文件的构成: 1.tcl文件 2.log文件 3.dbf文件(数据文件 ...
- WebDay18 MySQL存储过程 存储函数 触发器 事务
MySQL存储过程 存储函数 触发器 事务 一.MySQL存储过程和函数 1.存储过程和函数的概念 2.存储过程和函数的好处 3.存储过程和函数的区别 4.创建存储过程 5.调用存储过程 6.查看存储 ...
- sqlserver 触发器实例代码
何为触发器?在SQL Server里面也就是对某一个表的一定的操作,触发某种条件,从而执行的一段程序.触发器是一个特殊的存储过程. 常见的触发器有三种:分别应用于Insert , Update , D ...
- SQL触发器实例讲解1
SQL触发器实例1 定义: 何为触发器?在SQL Server里面也就是对某一个表的一定的操作,触发某种条件,从而执行的一段程序.触发器是一个特殊的存储过程. 常见的触发器有三种:分别应 ...
- SQL触发器实例讲解
定义: 何为触发器?在SQL Server里面也就是对某一个表的一定的操作,触发某种条件,从而执行的一段程序.触发器是一个特殊的存储过程. 常见的触发器有三种:分别应用于Insert , ...
最新文章
- springboot之异步调用@Async
- 简单的鼠标可拖动div 兼容IE/FF
- 架构师之路 — 分布式系统 — RPC 远程过程调用
- Launcher3自定义壁纸旋转后拉伸无法恢复
- 2018-2019-2 20175235 实验四《Android开发基础》实验报告
- APP开发者到期续费说明
- AzCopy – 上传/下载 Windows Azure Blob 文件
- python opencv 利用分水岭算法实现对物体的分割 图文详细注释版 以分割官网提供的硬币为例
- Arch Linux freemind中文乱码
- js ajax 表单异步提交
- IE浏览器打不开网页有什么解决的方法
- Food Webs - 网络中度及集聚系数实现
- 萤石云设备接入操作说明
- 帕斯卡齿轮机械计算机原理,20世纪的黑科技,上万个零件的老式机械计算器,复杂程度惊人!...
- Siebel应用数据结构层次
- 区块链靠什么开启下一个互联网传奇?迅雷链:回归技术
- 如何将Excel文件转换WPS格式?
- 计算机共享访问权限 xp,上面就是xp访问win7共享要密码的解决方法
- Linux下deb包和rpm包区别
- 成都榆熙:做拼多多电商如何优化用户消费体验?