触发更新多行 [英] trigger to update multiple rows

查看:92
本文介绍了触发更新多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ALTER trigger [dbo].[tri_memberLoginUpdate] on [dbo].[tbl_advisor_registration]
for update
as
declare @advId bigint;
declare @Name varchar(100);
declare @password varchar(100);
declare @status bigint;

select @advId=i.advisor_id from inserted i;
select @name=i.advisor_username from inserted i;
select @password=i.advisor_password from inserted i;
set @status=2;

update tbl_login set username=@name,password=@password,status=@status where user_Id=@advId and status=2







我正在使用此触发器,但它仅更新单行..




im using this trigger ,but its updating only single rows..

推荐答案

ALTER TRIGGER [dbo].[tri_memberLoginUpdate]
ON [dbo].[tbl_advisor_registration]
FOR  UPDATE
AS

    UPDATE T
    SET    t.USerName = i.advisor_username, t.Password =  = i.advisor_password
    FROM   tbl_login t
           INNER JOIN INSERTED i
                ON  i.advisor_id = t.User_id
                    AND t.Status = 2



i不认为有一个循环需要希望这可以解决你的问题


i don't think there is a loop needed hope this solves your problem


因为这里
where user_Id=@advId

你只传递单个id而不是多个id

you are only passing single id not multiple id


你必须在触发器中使用while循环来更新或插入多个记录



更多信息请访问...





而 - 环 - 内 - 一个触发到环通-全的-columns-of-table-in-sql [ ^ ]
You have to use while loop within the Trigger to update or insert multiple records

For more visit here...


while-loop-inside-a-trigger-to-loop-through-all-the-columns-of-table-in-sql[^]


这篇关于触发更新多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆