触发器:
触发器是数据库表的触发器,主要是在对表的插入、修改、删除等操作时执行的一段代码,用来作为该表的约束。
实例说明:
在一个问题上报案例中,当一个问题事件上报到数据库表中时,即在数据库表插入数据时,判断问题状态是0(审核)时,添加一个该问题事件的索引到另一个表中供查询使用。
代码如下:
ALTER TRIGGER [dbo].[InsertProblem] ON [dbo].[Problem]
AFTER INSERT
AS
declare @in_taskid varchar(13);
declare @in_areaid varchar(10);
declare @temp_coordinate varchar(10);
declare @temp_location nvarchar(30);
declare @temp_status varchar(10);
declare @temp_count int;
select @temp_status=status from inserted;
--set @in_areaid='100000';
set @temp_count=0;
if( @temp_status='0')
begin
--根据坐标计算得到areaid邮编
select @temp_coordinate= coordinate from inserted;
select @temp_location= location from inserted;
/**
begin
declare @area nvarchar(30);
declare myCusor cursor for select area from Area