SELECT 出表A中Name列的所有行,然后将这些内容全部插入到表B的Name列内。该怎么写?谢谢表A
================
ID    Name
1     David
2     Goodman
3     Spiderman
================表B
=============================
ID    Name    StartDateTime
=============================

解决方案 »

  1.   

    insert into b(name) select name from A
      

  2.   

    insert into b(name) select name from a;
      

  3.   

    insert into b(name) select name from a;
      

  4.   

      INSERT B(Name) SELECT name from A
      

  5.   

    若ID也插入,
    没有索引如下:
    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

    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
      

  6.   

    如果要对应StartDateTime 得值,那么考虑用游标来解决,不然,就简单的用sql插入就可以