加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sqlserver2000中触发器小实例!

发布时间:2020-12-12 15:28:43 所属栏目:MsSql教程 来源:网络整理
导读:--insert 触发器 create trigger tri_infoDetails_i on info_details after insert as ??? declare @id int begin ??? --delete from info_details where id= ??? select @id=id from inserted; ??? insert into info_details_index(TYPE,TITLE,content,POST

--insert 触发器

create trigger tri_infoDetails_i on info_details
after insert
as
??? declare @id int
begin
??? --delete from info_details where id=
??? select @id=id from inserted;
??? insert into info_details_index(TYPE,TITLE,content,POST_TIME,FLAG)
??? select type,title,getdate(),1 from info_details where id=@id;
??? --update info_details_index set content=content
end;

?

-- update触发器

--select top 0 type,getdate() as post_time,1? as flag? into info_details_index from info_details;
create trigger tri_infoDetails_u on info_details
after update
as
??? declare @id int
begin
??? if exists(select 1 from inserted)
??? ???? if exists(select 1 from deleted)
??? ???? begin
??? ??? select @id=id from inserted;
??? ??? insert into info_details_index(TYPE,FLAG)select type,-1 from info_details where id=@id;
??? ??? insert into info_details_index(TYPE,1 from info_details where id=@id;
??? ???? end
??? ??? ????
??? --update info_details_index set content=content
end


--delete触发器

create trigger tri_infoDetails_d on info_details after delete as ??? declare @id int begin ??? ??? ???? if exists(select 1 from deleted) ??? ???? begin ??? ??? ? ??? ??? insert into info_details_index(TYPE,FLAG) ??? ??? select type,-1 from deleted info_details ; ??? ???? end ??? ??? ???? ??? ? end

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读