insert tb select * from tb

解决方案 »

  1.   

    注意主键哦
    如果有自增列,可直接insert... select...
      

  2.   

    if object_id('tb')is not null drop table tb
    go
    create table tb(ID int identity,[name] varchar(10))
    insert tb select 'A'
    insert tb select 'B'
    insert tb select 'C'
    insert tb select 'D'
    insert tb select 'E'
    insert tb select 'F'
    insert tb([name]) select top 3 [name] from tb order by id --假設複製前三條
    select * from tb
    /*ID          name       
    ----------- ---------- 
    1           A
    2           B
    3           C
    4           D
    5           E
    6           F
    7           A
    8           B
    9           C(影響 9 個資料列)*/
      

  3.   

    id是自增的,就是要后面列的内容,想简单的增加数据,方便测试而已,没什么索引啊insert tb select * from tb
    用了这种,提示出错:
    insert  zz_lianxics  select *  from zz_lianxics  where id between 9 and 12 仅当使用了列列表并且 IDENTITY_INSERT 为 ON 时,才能为表'zz_lianxics'中的标识列指定显式值。
      

  4.   

    insert into tablename (a1,a2,a3....) (select top 10 a1,a2,a3....from tablename)