T-SQL UPDATE trigger help

Posted by Tan on Stack Overflow See other posts from Stack Overflow or by Tan
Published on 2010-03-12T11:08:53Z Indexed on 2010/03/12 11:17 UTC
Read the original article Hit count: 199

Filed under:
|

Hi iam trying to make an update trigger in my database. But i get this error every time the triggers trigs.

Error MEssage: The row value(s) updated or deleted either do not make the row unique or they alter multiple rows(3rows)

and heres my trigger

ALTER TRIGGER [dbo].[x1pk_qp_update]
        ON [dbo].[x1pk] FOR UPDATE
AS
BEGIN TRY
DECLARE @UserId int
      , @PackareKod int
      , @PersSign varchar(10)

    SELECT @PackareKod = q_packarekod
         , @PersSign = q_perssign
      FROM INSERTED

IF @PersSign IS NOT NULL
BEGIN
    IF EXISTS (SELECT * FROM [QPMardskog].[dbo].[UserAccount] WHERE [Account] = @PackareKod)
    BEGIN
    SET @UserId = (SELECT [UserId]
                     FROM [QPMardskog].[dbo].[UserAccount]
                    WHERE [Account] = @PackareKod)

        UPDATE [QPMardskog].[dbo].[UserAccount]
           SET [Active] = 1
         WHERE [Account] = @PackareKod

        UPDATE [QPMardskog].[dbo].[User]
           SET [Active] = 1
         WHERE [Id] = @UserId


    END
END

END TRY

But i only update one row in the table how can it says 3 rows. Please advise.

© Stack Overflow or respective owner

Related posts about tsql

Related posts about sql-server