What happens when I drop a clustered primary key in SQL 2005

微笑、不失礼 提交于 2019-12-20 00:44:10

问题


I've a PK constraint - a clustered index on two columns - which I am in the process of dropping. The command is still running after an hour. I would have thought that as I am just removing a constraint the operation would be nearly instantaneous. Can someone explain to me what is actually happening under the hood when I drop the PK?


回答1:


Clustered index is not "just a constraint", it's a storage method.

When you drop it, your data are being reordered from clustered storage to heap storage

Other indexes are being updated to refer to RID's instead of PRIMARY KEY values.




回答2:


The clustered index is the data, that would explain the time it is taking to run.




回答3:


A "CLUSTERED" index will physically write the records of your table in order on the hard drive. So dropping or changing that index would likely cause SQL Server to basically 'defrag' (reorder) your hard drive (well, at least the part where the data for that table is).

Please note, this answer is not perfectly technical... but it's meant to give you the "oh, that's kinda what's happening" answer which is usually way more than good enough.



来源:https://stackoverflow.com/questions/705504/what-happens-when-i-drop-a-clustered-primary-key-in-sql-2005

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!