--order by:yujinsheng
--time:2008-12-18
create trigger UpdateAtype
on a for update
as
declare @typeid int
declare @id int
--触发器语句中使用了两种特殊的表:deleted 表和 inserted 表,用于存储 DELETE 和 UPDATE 语句所影响的行的复本
select @id=id from deleted
select @typeid=typeid from inserted
--也可理解为更新一行数据就是先删除后插入,获取删除前id,和插入后的状态值typeid
if(@typeid=2 or @typeid=0)
update a set type=0 where id=@id
else
update a set type=1 where id=@id
---a表存在两个状态数值(type和typeid)
---当更新typeid=1 时候 type=1
---当更新typeid=2或typeid=0时候 type=0
---SQL Server™ 2000 不允许 AFTER 触发器引用 inserted 和 deleted 表中的 text、ntext 或 image 列
--(管理)企业管理器-->右键你的表-->所有任务-->管理触发器