a表结构如下:
aid, PK
name,
gender
birth
postID
ptID
……
B表结构如下:
bid,PK
idnum
name
orgname
gender
birth
issue
joindate
……
A表是空表,现在想把B表中与A表相同的字段(name,gender,birth)的数据拷贝到A表中,用SQL如何实现,谢谢
aid, PK
name,
gender
birth
postID
ptID
……
B表结构如下:
bid,PK
idnum
name
orgname
gender
birth
issue
joindate
……
A表是空表,现在想把B表中与A表相同的字段(name,gender,birth)的数据拷贝到A表中,用SQL如何实现,谢谢
SELECT [NAME],[GENDER],[BIRTH] FROM B
select name,gender,birth
from b
--加个限制条件,反复执行都没有问题的!insert into a(aid,name,gender,birth) select bid,name,gender,birth from b bb
where not exists(select 1 from a where bb.bid=aid )
insert into a(aid,name,gender,birth) select bid,name,gender,birth from b bb
where not in(select bid from a)