qw123
create table a
(
id int primary key not null identity(1,1),
name varchar(20) unique,
pwd varchar(30)
)
create table b
(
id int primary key not null identity(1,1),
name varchar(20) unique,
info varchar(30)
)
insert into a values ('qw','123')
insert into b values ('qw',Null)
select * from a
select * from b
1 qw 123
1 qw NULL
sql替换:
根据你的要求,不应该用insert
而是要用update
代码如下:
update b set info =(select pwd from a,b where a.name=b.name)
(1 行受影响)
select * from a
select * from b
结果预期!
呵呵
其他写法:
update b set info =(select pwd from a join b on a.name=b.name)
***同学习!