sqlserver触发器问题
两个数据库project、sso
project中表s_user中修改密码字段触发,sso中表sso_user修改相同用户的密码。
create TRIGGER trg_sso_user
ON [project].[dbo].[S_USER]
for UPDATE
AS
DECLARE
@username nvarchar(50),
@password nvarchar(50)
select @username = user_name, @password = password from deleted,
update sso.dbo.sso_user set password = @password where user_name = @username
报错!说update附近有语法错误,小白求教育啊!
SQL?Server
数据库
sso
密码
------解决方案--------------------select @username = user_name, @password = password from deleted
把后面的逗号去掉
------解决方案--------------------你的deleted后面跟了一个逗号,是多余的
另外你可以直接一句话更新
create TRIGGER trg_sso_user
ON [project].[dbo].[S_USER]
for UPDATE
AS
update sso.dbo.sso_user set password = d.password
from deleted d
where user_name = d.user_name