A表中有 name,no
B表中有 name,no
A表中有预先写好的name,no
想要实现当B表中输入no后实时在B表中更新与之对应name
我用的是SQL 2008
4 个解决方案
#1
update b set name=a.name
from a join b on a.no=b.no
and b.no=刚刚插入的no
#2
有没有触发器可以让这个过程自动进行
#3
这是我编写出来的触发器,测试有效,回报社会,希望对你们有用
CREATE TRIGGER [dbo].[gengxin]
ON [dbo].[b]
FOR INSERT
AS
IF Update(no)
begin
update b
SET
name=A.name
FROM
b AS B,a AS A
WHERE B.no=A.no
end
CREATE TRIGGER [dbo].[gengxin]
ON [dbo].[b]
FOR INSERT
AS
IF Update(no)
begin
update b
SET
name=A.name
FROM
b AS B,a AS A
WHERE B.no=A.no
end
#4
如果你是在A表插入的时候写入,可以在写入的时候output into B表实现
#1
update b set name=a.name
from a join b on a.no=b.no
and b.no=刚刚插入的no
#2
有没有触发器可以让这个过程自动进行
#3
这是我编写出来的触发器,测试有效,回报社会,希望对你们有用
CREATE TRIGGER [dbo].[gengxin]
ON [dbo].[b]
FOR INSERT
AS
IF Update(no)
begin
update b
SET
name=A.name
FROM
b AS B,a AS A
WHERE B.no=A.no
end
CREATE TRIGGER [dbo].[gengxin]
ON [dbo].[b]
FOR INSERT
AS
IF Update(no)
begin
update b
SET
name=A.name
FROM
b AS B,a AS A
WHERE B.no=A.no
end
#4
如果你是在A表插入的时候写入,可以在写入的时候output into B表实现