加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

SQL Server触发器和事务用法示例

发布时间:2020-12-12 09:15:27 所属栏目:MsSql教程 来源:网络整理
导读:本篇章节讲解SQL Server触发器和事务用法。供大家参考研究具体如下: 新增和删除触发器 0) begin insert into t_c2 select * from inserted; end else if(@DELETECOUNT > 0) begin delete t_c2 where exists(select temp.cid from deleted temp wh

本篇章节讲解SQL Server触发器和事务用法。分享给大家供大家参考,具体如下:

新增和删除触发器

0) begin insert into t_c2 select * from inserted; end else if(@DELETECOUNT > 0) begin delete t_c2 where exists(select temp.cid from deleted temp where temp.cid=t_c2.cid); end end

更新触发器和事务

事务主要用在数据的保护,在多表更新时,事务保存所有事务下的更新语句就不会提交,数据也就不能更新成功

0) begin begin transaction triUpdate --定义事务 declare @cname varchar(100); select @cname = cname from inserted; --保存更新后的内容 update t_c2 set cname = @cname where cid = (select cid from deleted); --更新 if (@@error <> 0) begin rollback transaction triUpdate; --事务回滚 end else begin commit transaction triUpdate; --事务提交 end end end

存储过程

游标

视图

定义方法

@str2) set @returnStr = 'true' return @returnStr end select dbo.funName(...,...)

定义表变量

case when then 条件统计时的使用

希望本文所述对大家SQL Server数据库程序设计有所帮助。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读