Home >Database >Mysql Tutorial >SqlServer添加触发器不让删除数据

SqlServer添加触发器不让删除数据

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 17:42:211643browse

SqlServer添加触发器不让删除数据 触发器是:instead of delete 类型,注意了:instead类型的触发器相当于: DELETE命令过来后,直接走触发器中的代码,再往下,没有了 就是说,这个触发器会屏蔽掉你所有的DELETED命令。而只会执行一下触发器中的代码。 如果

SqlServer添加触发器不让删除数据

触发器是:instead of delete 类型,网站空间,注意了:instead类型的触发器相当于:
DELETE命令过来后,美国服务器,直接走触发器中的代码,再往下,没有了……
就是说,这个触发器会屏蔽掉你所有的DELETED命令。而只会执行一下触发器中的代码。

如果你把这个触发器中的代码都注释掉,服务器空间,就相当于:屏蔽所有的DELETE命令。

 

Create trigger [dbo].[trg_del] on [dbo].[drv_user]
instead of delete
AS
BEGIN
declare @cou int
select @cou=count(*) from deleted;
if (@cou>0)
RAISERROR('数据不允许删除!', 16, 1)
END

posted on

Statement:
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