SQL2008创建表,设置主键时系统默认在主键上创建聚簇引索。怎样,在不变更主键的情况下,删除这个默认的聚簇引索?我的目的是想在其它列上重新建立一个聚簇引索,小弟菜鸟,谢谢解答!

解决方案 »

  1.   

    for example,create table dds
    (c1 int not null,
     c2 int not null
     constraint pk_dds primary key nonclustered (c1)
    )create clustered index ix_dds_c2 on dds(c2)
    sp_helpindex dds/*
    index_name          index_description                                        index_keys
    ------------------  ------------------------------------------------------  --------------
    ix_dds_c2           clustered located on PRIMARY                                c2
    pk_dds              nonclustered, unique, primary key located on PRIMARY        c1
    */
      

  2.   

    直接drop掉聚集索引然后在需要的列上create clustered index即可
      

  3.   

    我都试过了
    1#设置主键时,指定了nonclustered,所以就不存在设置主键时默认引索问题,方法可行。
    2#方法针对1# nonclustered建表方式是行的通的。
    但是我遇到的问题是,建表的时候没有指定nonclustered,例如:
    create table dds
    (c1 int primary key not null,
     c2 int not null
    )
    结果就是主键名和聚簇引索名相同(问题关键所在),然后我再:
    drop index 聚簇引索名 on dds
    提示消息:
    不允许对索引 '***' 显式地使用 DROP INDEX。该索引正用于 PRIMARY KEY 约束的强制执行。
    这该怎么解决???
      

  4.   

    其实很简单,先把pk删了,这样聚集索引也没了,然后先创建聚集索引,然后创建PK。