本文最后更新于 2001 天前,如遇到任何问题欢迎在评论区留言呀!
触发器
定义
create trigger trigger_name on table_name for manipulation
as
begin
declare @variable1 data_type1, @variable2 data_type2
select @variable1=variable1,@variable2=variable2 from inserted
select @Variable1=variable1,@variable2=variable2 from deleted
%条件语句或循环语句(过程化 SQL)
end
说明:
以上trigger_name、table_name、manipulation、 variable、data_type按实际需要替换。其中manipulation包括insert、delete、update。
注意对inserted和deleted这两张表的使用。
调用
由 DBMS 自动调用。
自定义函数
定义
create function function_name(arg1,arg2) returns table
as
return(
%select 子句
)
说明:以上function_name、arg(可以为空)按实际需要替换。因自定义函数最常用的返回类型就是table,这里就以此为例。
调用
2.1 中自定义函数返回的是一张表,因此,通过 select 子句即可完成调用
select * from function_name()