(
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)
***同學習!