Home > Database > Mysql Tutorial > mssql server 判断触发器正在处理的是插入,删除还是更新触发

mssql server 判断触发器正在处理的是插入,删除还是更新触发

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 17:49:02
Original
1251 people have browsed it

本文章介绍了关于mssql server 判断触发器正在处理的是插入,删除还是更新触发 ,有需要学习的同学可以参考一下下哦。

 代码如下 复制代码

--宣告两个变量
DECLARE @D BIT = 0
DECLARE @I BIT = 0

--如果在DELETED内部临时触发表找到记录,说明旧数据被删除 
IF EXISTS(SELECT TOP 1 1 FROM DELETED)
SET @D = 1

--如果在INSERTED内部临时触发表找到记录,说明有新数据插入 
IF EXISTS(SELECT TOP 1 1 FROM INSERTED)
SET @I = 1 

--如果两个表都有记录,说明是执行更新触发
IF @I = 1 AND @D = 1 
PRINT(N'更新。')

--如果变量@I值被变更为1,而变量@D没有变更,说明触发器是执行插入触发 
IF @I = 1 AND @D = 0
PRINT(N'插入')

--下面判断成立,说明说明触发器是执行删除触发 
IF @I = 0 AND @D = 1
PRINT(N'删除')

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
sql file
From 1970-01-01 08:00:00
0
0
0
php - Overhead of prepare vs sql?
From 1970-01-01 08:00:00
0
0
0
Print sql statement
From 1970-01-01 08:00:00
0
0
0
Pass array to SQL insert query using PHP
From 1970-01-01 08:00:00
0
0
0
sql optimization or
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template