创建一个insert触发器,在insert触发器中,可以引用一个名为
如何创建触发器insert、update、delete
使用create
trigger命令创建触发器
语法如下
create
trigger
trigger_name
on{table|view}
[with
encryption]
{
{{for|after|insted
of}{[delete][,][insert][,][update]}
[not
for
replication]
as
[{if
update
(column)
[{and|or}
update
(column)]
[...n]
|if
(columns_updated(){bitwise_operator}updated_bitmask)
{comparison_operator}column_bitmask[...n]
}]
sql_statement
[...n]
}
}
至于存储过程是使用create
procedure创建存储过程的
语法如下
create
procedure
procedure_name[;version
number]
[{@parament
date_type}
[varying]
[=default
value][output]
][,...n]
[with
{recompite|encryption|recompile,encryption}]
[for
replication]
as
sql_statement
[...n]
帮帮忙----触发器 创建Insertde 触发器
1.
create table cust_test(CustomerID char(5) primary key,Custcity varchar(20),custname varchar(20),cstatus int,cstorage int,cdate datetime)
create table order_test(CustomerID char(5),orderid char(10) primary key,Ordernames char(10),OStatus int,Quanity int,Odate datetime)
2.
create trigger tR_order_insert
on order_test for insert
as
begin
update a
set a.Cstorage=a.Cstorage-isnull(b.Quanity)
from cust_test a,order_test b
where a.CustomerID=b.CustomerID
end
3.
create trigger tR_order_insert
on order_test instead of insert
as
begin
IF exists(Select 1 from cust_test where customerid=(Select customerid from inserted) and status=1)
return
else
insert into order_test select * from inserted
end
关于创建一个INSERT触发器
直接给出sql 代码吧,其中cno就是代表班级号
create trigger student_trigger
on student
for insert
as
if (select cno from inserted) not in (select cno from class)
begin
rollback transaction
end