--建立测试数据
create table table11(
xh int identity,
xm varchar(10),
kc varchar(10),
cj int
)
gocreate table newtable(
xh int identity(1000,1),
xm varchar(10),
kc varchar(10),
cj int,
kscs varchar null
)
go--插入数据
insert into table11 select '张三','物理',82
union all select '张三','化学',74
union all select '李四','英语',55
union all select '王五','物理',66
union all select '孙六','语文',72
union all select '孙六','化学',48insert into newtable select '何大','英语',82,null
union select '李小','化学',74,null--插入语句,得到newtable新的记录
insert newtable(xm,kc,cj) 
select table11.xm,table11.kc,table11.cj from table11

解决方案 »

  1.   

    同意楼上的,只要将NEWTABLE的id设置为identity(1000,1)就可以了
      

  2.   

    可是我现在的NEWTABLE表已经是存在的,而且里面有一定的数据,是一个软件的后台数据库,有没有办法在不新建表的基础上,把这个ID字段插入的时候给递增呢
      

  3.   

    这个NEWTABLE表中的ID字段原来是DEMICAL型的
      

  4.   

    借用楼上的:
    --建立测试数据
    create table table11(
    xh int identity,
    xm varchar(10),
    kc varchar(10),
    cj int
    )
    gocreate table newtable(
    xh int identity(1,1),
    xm varchar(10),
    kc varchar(10),
    cj int,
    kscs varchar null
    )
    go--插入数据
    insert into table11 select '张三','物理',82
    union all select '张三','化学',74
    union all select '李四','英语',55
    union all select '王五','物理',66
    union all select '孙六','语文',72
    union all select '孙六','化学',48insert into newtable select '何大','英语',82,null
    union select '李小','化学',74,null
    --插入语句,得到newtable新的记录
    set identity_insert newtable  on
    insert newtable(xh,xm,kc,cj) 
    select xh+1000,xm,kc,cj from table11
      

  5.   

    那直接把table的数据考到newtable来不就行了吗?
    而且你学号没有规律,但是它总代表一定的含义把,也就是你可以把它直接复制到新表就可以;
    set identity_insert newtable  on
    insert newtable(xh,xm,kc,cj) 
    select xh,xm,kc,cj from table11
      

  6.   

    但是我这样写,他说我NEWTABLE没有标识属性,无法执行SET操作,因为我现在的NEWTABLE的表结构是固定的,其中的ID是数值型的,如果ID现在已经标到3005了,接下去插入的数字就是从3006开始,每一条步进1,那我要怎么写呢,谢谢