create trigger tr_a_insert
on a
for insert
asupdate b 
set ...                             --楼主没说怎么更新
from inserted i,b
where i.type=b.id
and i.type in (1,2,3)go

解决方案 »

  1.   

    create trigger tr_a_insert
    on a
    for insert
    as
    begin
     delcare @type int
     select @type =type from inserted
     --更新
     update b set ....... where B.ID=@type 
    end
    go
      

  2.   

    CREATE TRIGGER TR_INSERT ON TA AFTER INSERT
    AS
    BEGIN
      DECLARE @A VARCHAR(10),@SQL VARCHAR(8000)
      SELECT @A=TYPE FROM INSERTED
      SET @SQL='UPDATE TB SET ....... WHERE ID='''+@A+'''' --没说要什么更新
      ESEC (@SQL)  
    END
      

  3.   

    谢谢楼上各位,但我想要的不是这个,我希望的是想要 if    .. then ..  if ...then  ...这种,因为只是想type=某几项时才作更新
      

  4.   

    create trigger tr_a_insert
    on a
    for insert
    as
    begin
     delcare @type int
     select @type =type from inserted
     --更新
     if (@type = 1)
     begin
       update b set ....... where B.ID=@type 
     end
     else if (@type = 2)
     begin
       update b set ....... where B.ID=@type 
     end
     ........
     else
     begin
       update b set ....... where B.ID=@type 
     end
    end
    go
      

  5.   

    create trigger tr_a_insert
    on a
    for insert
    as
    begin
      delcare @type int
      select @type =type from inserted
      if @type=1
         update b set .... where B.id=1
      if @type=2
         update b set .... where B.id=2
      if @type=3
         update b set .... where B.id=3 
    endgo
      

  6.   

    CREATE TRIGGER TR_INSERT ON TA AFTER INSERT 
    AS 
    BEGIN 
      DECLARE @A VARCHAR(10),@SQL VARCHAR(8000) 
      SELECT @A=TYPE FROM INSERTED 
      SET @SQL='UPDATE TB SET ....... WHERE ID='''+@A+'''' --没说要什么更新 
      if CHARINDEX(','+@A+',',',1,2,3,')>0  --等1或2或3时更新
        ESEC (@SQL)  
    END