SELECT 出表A中Name列的所有行,然后将这些内容全部插入到表B的Name列内。该怎么写?谢谢表A
================
ID Name
1 David
2 Goodman
3 Spiderman
================表B
=============================
ID Name StartDateTime
=============================
================
ID Name
1 David
2 Goodman
3 Spiderman
================表B
=============================
ID Name StartDateTime
=============================
没有索引如下:
insert into B(ID,Name,StartDateTime)
select ID,Name,getdate()
from A
有索引如下:
insert into B(ID,Name,StartDateTime)
select ID,Name,getdate()
from A
left outer join
B
on A.ID = B.Id
where B.ID is null若ID 自增的,
declare @max int
select @max = isnull(max(ID),0) from B
insert into B(ID,Name,StartDateTime)
select row_number() over(order by ID asc)+@max,Name,getdate()
from A