如何删除在主键列上自动创建的聚簇索引,但保留该列的主键约束? [英] How to drop clustered index that gets created automatically on primary key column but keeping primary key constraint on that column as it is ?
问题描述
请帮助如何删除在主键列上自动创建的聚簇索引?
但与此同时,我希望保留该列上的主键约束。这是因为我想在某个不同的列上创建聚簇索引。(非主键列)。
我尝试过的方法:
我尝试删除在主键上创建的聚簇索引。
但它给了我以下错误:
索引't1.PK__t1__3214EC070AD2A005'上不允许显式DROP INDEX。它被用于PRIMARY KEY约束实施。
Please help how to drop clustered index that gets created automatically on primary key column ?
But at the same time, I want to retain the primary key constraint on that column as it is. This is because i want to create clustered index on some different column.(non primary key column).
What I have tried:
I tried dropping clustered index which got created on primary key.
But it gave me below error :
An explicit DROP INDEX is not allowed on index 't1.PK__t1__3214EC070AD2A005'. It is being used for PRIMARY KEY constraint enforcement.
推荐答案
An索引't1.PK__t1__3214EC070AD2A005'上不允许使用显式DROP INDEX。它用于PRIMARY KEY约束实施。
An explicit DROP INDEX is not allowed on index 't1.PK__t1__3214EC070AD2A005'. It is being used for PRIMARY KEY constraint enforcement.
错误消息告诉您为什么不能删除主键的索引。
为什么这是一个在另一列中使用非聚集索引的问题?
The error message tells you why you can't drop the index of a primary key.
Why is it a problem to use non clustered index in another column ?
目前我只看到以下序列来解决你对_non empty_数据库的请求:
For the moment I see only the following sequence to solve your request for a _non empty_ database:
1. Drop foreign key constraint(s) referencing the Primary, N times
ALTER TABLE Detail DROP CONSTRAINT FK_Detail_Master;
2. ALTER TABLE Master DROP CONSTRAINT PK_Master;
3. ALTER TABLE Master ADD CONSTRAINT PK_Master PRIMARY KEY NONCLUSTERED (Id);
4. Recreate foreign key constraint(s), N times
ALTER TABLE Detail ADD CONSTRAINT FK_Detail_Master FOREIGN KEY (Master_Id) REFERENCES Master (Id);
我希望它有所帮助。
I hope it helps.
这篇关于如何删除在主键列上自动创建的聚簇索引,但保留该列的主键约束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!