CREATE TRIGGER [usageinsert] ON [dbo].[t_res_usage_info]
AFTER INSERT //插入后执行
AS
begin
declare every_use_cursor cursor local forward_only for
select res_typ from inserted //建立游标
declare @myres_type_name varchar(20);
open every_use_cursor
fetch next from every_use_cursor into @myres_type_name
while @@fetch_status = 0 //判断返回行
begin
if @myres_type_name is not null
begin
if not exists(select res_type_name from t_res_type where res_type_name=@myres_type_name)
begin
insert t_res_type(res_type_name,remark)values(@myres_type_name,'') ;
end;
end;
fetch next from every_use_cursor into @myres_type_name;
end;
close every_use_cursor //关闭游标
deallocate every_use_cursor //释放游标
end;