trigger.sql

来自「C# 论坛 accesss数据库,支持SQL2000」· SQL 代码 · 共 46 行

SQL
46
字号
-- ================ Post Trigger ================
-- Description:Set ParentId and Times when Posted
-- Author:kid
-- ==============================================
CREATE TRIGGER Trig_Forum_Info
ON Forum_Info
WITH ENCRYPTION
for insert 
as 
begin
declare @id int 
declare @Parentid int 
select @id=Forum_Info_Id from inserted 
select @Parentid=Forum_Info_ParentId from inserted 


    update Forum_Info set Forum_Info_RootId=@id where Forum_Info_Id=@id and @Parentid=0
    Update Forum_Info set Forum_Info_Times=@id 
    where Forum_Info_RootId= @id and @Parentid=0

    update Forum_Info set Forum_Info_RootId=
    (select top 1 Forum_Info_RootId from Forum_Info where Forum_Info_Id=@Parentid) 
    where Forum_Info_Id=@id and @Parentid<>0

    Update Forum_Info set Forum_Info_Times=@id 
    where Forum_Info_RootId= (select top 1 Forum_Info_RootId from Forum_Info where Forum_Info_Id=@Parentid)  and @Parentid<>0
end
-- ================== BookMarks Trigger ==================
-- Description:Set BookMark Name when BookMarks been Added
-- Author:kid
-- =======================================================
CREATE TRIGGER Trig_Forum_BookMarks
ON Forum_BookMarks
WITH ENCRYPTION
for insert 
as 
begin

declare @Title varchar(255)
declare @id int 

select @id=Forum_Info_Id from inserted 
select @Title=Forum_Info_Title from Forum_Info where Forum_Info_Id=@id
update Forum_BookMarks set Forum_BookMark_Name=@Title,Forum_BookMark_Des=@Title where Forum_Info_Id=@id

end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?