一个触发器ALTER TRIGGER AInsertAffter ON kbsys_KB AFTER INSERT,UPDATE    
一个触发器
AS
一个触发器
begin
一个触发器    
declare @Keyword Nvarchar(4000)
一个触发器    
declare @key Nvarchar(4000)
一个触发器    
declare @t int
一个触发器    
declare @keyWordCreatedBy Nvarchar(4000)
一个触发器    
--set @Keyword = inserted.kbKeyWord
一个触发器
    select @Keyword = kbKeyWord from inserted
一个触发器    
--set @keyWordCreatedBy = inserted.kbCreatedBy
一个触发器
    set @t = CHARINDEX(',',@Keyword)
一个触发器    
if (@Keyword is nullreturn
一个触发器    
while(@t <> 0)
一个触发器    
begin
一个触发器        
set @key = SUBSTRING(@Keyword,1,@t - 1)
一个触发器        
set @Keyword = SUBSTRING(@Keyword,@t + 1,len(@Keyword- @t)
一个触发器        
if not exists (select * from kbsys_KeyWord where keyWordContent = @key)
一个触发器        
begin
一个触发器            
insert into kbsys_KeyWord (keyWordContent,keyWordCreatedBy)   
一个触发器            
select @key,kbCreatedBy from inserted  
一个触发器        
end
一个触发器        
-- 找下一个逗号
一个触发器
        set @t = CHARINDEX(',',@Keyword)
一个触发器    
end
一个触发器    
if (@Keyword = ''return
一个触发器    
if not exists (select * from kbsys_KeyWord where keyWordContent = @Keyword)
一个触发器    
begin
一个触发器            
insert into kbsys_KeyWord (keyWordContent,keyWordCreatedBy)   
一个触发器            
select @Keyword,kbCreatedBy from inserted  
一个触发器    
end
一个触发器
end

相关文章: