日期:2014-05-17  浏览次数:20525 次

关于sqlserver update触发器大数据量更新的问题,在线等
SQL code

CREATE trigger [dbo].[t_gpcr_bjd] on [syf].[dbo].[gpcr_bjd] for update 
as 
declare @id int 
BEGIN
    IF NOT UPDATE(isexsit)
    select @id =id from inserted
    BEGIN 
        update [syf].[dbo].[gpcr_bjd] set isexsit = 1 where id = @id
    END 
END



问题: 当修改少数据量的时候,是可行的,修改大数据量的时候却只将第一行isexsit至为1,求解

------解决方案--------------------
SQL code

CREATE trigger [dbo].[t_gpcr_bjd] on [syf].[dbo].[gpcr_bjd] for update 
as 
declare @id int 
BEGIN
    IF NOT UPDATE(isexsit)
    
    BEGIN 
        update [syf].[dbo].[gpcr_bjd] set isexsit = 1 where id in (select id from inserted)
    END 
END

------解决方案--------------------
SQL code
CREATE TRIGGER [dbo].[t_gpcr_bjd] ON [syf].[dbo].[gpcr_bjd]
  FOR UPDATE
AS
BEGIN
  IF NOT UPDATE(isexsit) 
    BEGIN 
      UPDATE  a
      SET     a.isexsit = 1
      FROM    [syf].[dbo].[gpcr_bjd] AS a,INSERTED AS i
      WHERE   a.id = i.id
    END 
END

------解决方案--------------------
CREATE trigger [dbo].[t_gpcr_bjd] on [syf].[dbo].[gpcr_bjd] for update 
as 
BEGIN
IF NOT UPDATE(isexsit)
BEGIN 
update a set isexsit = 1 
from [syf].[dbo].[gpcr_bjd] a, inserted b where a.id=b.id
END 
END