有两张表一张dept一张xsxx现在创建触发器,触发器要求当我更改dept里的列deptcode时,触发器会自动更新xss表中yxsh的值
我的触发器:
CREATE TRIGGER [ tri_dept ] ON [dbo].[dept]
FOR update
AS
begin
declare @deptcode char(20)
select @deptcode=dbo,dept.deptcode from inserted
if exists(select yxsh from xsxx where yxsh=dbo.dept.deptcode)
update xsxx set yxsh=@deptcode where yxsh=dbo.dept.deptcode
end
但是他显示错误为向变量赋值select语句不能和检索结合使用我想问一下原因谢谢~~
我的触发器:
CREATE TRIGGER [ tri_dept ] ON [dbo].[dept]
FOR update
AS
begin
declare @deptcode char(20)
select @deptcode=dbo,dept.deptcode from inserted
if exists(select yxsh from xsxx where yxsh=dbo.dept.deptcode)
update xsxx set yxsh=@deptcode where yxsh=dbo.dept.deptcode
end
但是他显示错误为向变量赋值select语句不能和检索结合使用我想问一下原因谢谢~~
CREATE TRIGGER [ tri_dept ] ON [dbo].[dept]
FOR update
AS
begin
declare @deptcode char(20)
select @deptcode=dbo,dept.deptcode from inserted
if exists(select yxsh from xsxx where yxsh=@deptcode)
update xsxx set yxsh=@deptcode where yxsh=@deptcode
end
CREATE TRIGGER [ tri_dept ] ON [dbo].[dept]
FOR update
AS
begin
declare @deptcode char(20)
select @deptcode=dbo,dept.deptcode from inserted //,改为.
if exists(select yxsh from xsxx where yxsh=@deptcode)
update xsxx set yxsh=@deptcode where yxsh=@deptcode
end