SQL Server 中的复合聚集索引
我有一个表,其中 IDENTITY 列作为主键(经典 ID 列)。
SQL Server 自动为该主键创建聚集索引。
我的问题是:
- 我可以有一个包含更多列的唯一 CLUSTERED INDEX 组合吗?
如果是,我如何删除默认的聚集索引并使用此属性重新创建一个新索引。
感谢您的支持
I have a table with a IDENTITY Column as Primary Key (a classic ID column).
SQL Server create automatically a Clustered Index for that Primary Key.
My question is:
- Can I have a only single CLUSTERED INDEX composite with more columns?
If yes, how can I drop the default clustered index and recreate a new one with this attributes.
Thanks for your support
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,每个表只能有一个聚集索引 - 数据在物理上按该索引排列,因此不能有多个。
然而,我不建议使用复合聚集索引。为什么?因为聚集索引应该始终是:
INT IDENTITY 作为聚集索引是完美的 - 我建议您保持这种方式。
聚集索引列(或列集)也会添加到同一个表上每个非聚集索引的每个条目中 - 因此,如果您将聚集索引设置得很大,例如 20、50 字节或更多,那么您就开始浪费磁盘和服务器内存中的大量空间,这通常会降低系统性能。
在这里阅读有关聚集索引的所有内容以及它们应该成为良好的聚集索引:
Yes, you can only have a single clustered index per table - the data is physically arranged by that index, so you cannot have more than one.
I would however not advise to use a composite clustered index. Why? Because the clustered index should always be:
INT IDENTITY is perfect as a clustered index - I would advise you keep it that way.
The clustered index column (or set of columns) is also added to each and every entry of each and every nonclustered index on that same table - so if you make your clustered index large, 20, 50 bytes or more, you begin to be wasting a lot of space - on disk and in your server's memory, which generally degrades your system performance.
Read all about clustered indices and what they should be to be good clustered indices here: