Table A 有primary key(a+b+c),同时也是聚簇索引,,现在我想把primary key 变成(a+b+c+d)。有什么方法呢?我尝试过删除约束,不过不行,弹出it is published and replication.有什么解决方法吗?

解决方案 »

  1.   

    取消主键  再设置
    alter table a add constraint <主键名> primary key(a,b,c,d)
      

  2.   


    create table #t(id1 int not null,id2 int not null,id3 int not null,id4 int not null,
    constraint pk_x primary key (id1,id2,id3)
    );
    insert into #t select 1,2,3,4;alter table #t drop constraint pk_x;alter table #t add constraint pk_x primary key(id1,id2,id3,id4);
      

  3.   

    --查看主键
    SELECT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME='tb'
    --删除主键
    alter table 表名 drop constraint 主键名
    --添加主键
    alter table 表名 add constraint 主键名 primary key (column1,column2,....,column)