set identity_insert on    //强制插入标识打开..................set identity_insert off //用完关闭

解决方案 »

  1.   

    1,先添加一个字段,设置为自动增一,比如叫id2
    2,select id,id2 into abc from yourtablename--保存关系;
    3,先删除这些关联的约束;
    4,删除刚才建立的id2,删除id,然后重新建立id自动增一,
    5,更新子表:update 子表 set id=t2.id2 from 子表t1, abc t2 where t1.id=t2.id
      

  2.   

    问题是必需得改,速度太慢了!!TO:chinaandys(风流泪,雨含笑) ........详细点。
      

  3.   

    TO:solidpanther(╃╄╃我爱机器猫╄╃╄) 
        有一个自递增列,还能加一个这样的列吗?
      

  4.   

    先把原来的id自动增一的属性去掉,不删除数据,再加一个id2自动增一
      

  5.   

    alter table 主表
    drop constraint 外键约名束
    go
    alter table 主表
    drop constraint 主键约名束
    go
    alter table 主表
    add tmpid identity(1,1) int,not null
    go
    update b set b.id=a.tmpid from 主表 a,从表 b where a.id=b.id
    go
    alter table 主表
    alter column id identity(1,1) int not null
    go
    alter table 主表
    add constraint pri_id primary key(id)
    go
    alter table 从表
    add constraint for_id foreign key(id) references 从表(id)
    go
    alter table 主表
    drop column tmpid
    go
      

  6.   

    alter table 从表
    drop constraint 外键约名束
    go
    alter table 主表
    drop constraint 主键约名束
    go
    alter table 主表
    add tmpid identity(1,1) int,not null
    go
    update b set b.id=a.tmpid from 主表 a,从表 b where a.id=b.id
    go
    alter table 主表
    alter column id identity(1,1) int not null
    go
    alter table 主表
    add constraint pri_id primary key(id)
    go
    alter table 从表
    add constraint for_id foreign key(id) references 从表(id)
    go
    alter table 主表
    drop column tmpid
    go