现在要通过无重复选择entityid,通过实体ID插入数据,也就是如下数据 
1 , 3, 5   | 2, 3, 5| 3,4,5|                   
 第一条为主码 1,2,3,为主码 
第二条3,3,4是实体ID
通过选择不同实体ID 3,4 插入两条数据 如: 4,3,1 | 5,4,1 主码是auto增长 大家有谁知道怎么写条sql语句 

解决方案 »

  1.   

    這樣?Create table T(ID int identity,Col1 int,Col2 int)--第1列為自增主碼
      

  2.   

    基本sql 就可以了  也就是找到不同entityid 然后加入entityid个同样数据
      

  3.   

    create table tb(id int identity(1,1) primary key,obj_id int,col int)
    go
    insert into tb
    select 3,5 union all
    select 3,5 union all
    select 4,5
    go
    select * from tb
    /*
    id          obj_id      col
    ----------- ----------- -----------
    1           3           5
    2           3           5
    3           4           5(3 行受影响)*/
    go
    drop table tb
      

  4.   

    能就是sql么 我这边不是MSSQL 而且与具体数据无关 类似insert into table1
    select distinct entityid ,1 ..(其它你想设定的内容)..from table1 
      

  5.   

    insert into attribute_info values (id, entityid, 0, 'Managed entity id', 2, 3, 0, '') from select distinct entityid from attribute_info
    id 是自动增长 entityid 是 select 后面选的
    帮忙修改下
      

  6.   

    ID自动增长 在后面插入的时候就不写就 OK了
      

  7.   

    insert into
     attribute_info 
    select
     distinct entityid, 0, 'Managed entity id', 2, 3, 0, ''
    from
      attribute_info