标签:begin bsp ash tab trigger server style end ted
触发器
一个特殊的存储过程,无法直接调用,而是通过增删改的动作来触发,一个表的一个动作只能有一个触发器
create table users
(
ids int primary key identity(1,1),
name nvarchar(10),
class nvarchar(10),
)
create table class
(
class_code nvarchar(10) primary key,
class_name nvarchar(10),
)
delete from users where ids=1
方法1:
create trigger user_delete ——针对哪一个表的哪一个动作
on users ——针对哪一个表的触发器
for delete ——针对哪一个动作之后的触发器
as
select * from users ——针对哪一个动作之后执行替换
方法2:
create trigger users1_delete
on users
instead of delete
as
select * from users
select * from deleted
declare @a nvarchar(10);
select @a=ids from deleted;
if @a>5
begin
select ‘太丑了,删不了‘
end
else
begin
delete from users where ids=@a
end
标签:begin bsp ash tab trigger server style end ted
原文地址:http://www.cnblogs.com/weiyu11/p/6559534.html