忘記是什麼時候聽到這句話,但一直會想起 : 理論上要用密度低的欄位作為Primary Key.
我想這句話應該要針對原先預設的Primary Key是Cluster Index.
Cluster Index才是選擇性要高的原因.
因為關係Physical Data的排列問題.
如果Primary Key不是Cluster Index,那他就與要建立Cluster Index沒關係。
那他要考慮的選擇性高(密度低)就是他沒得考慮,他一定要選擇性高(密度低),否則就會違反他PK所帶有Unique的特性.
所以我猜測,選擇性高的欄位當Primary Key(其實就是要密度為1,所以我通常直接使用INT Identity),就是因為一兼二顧,摸蜊仔兼洗褲。
PK是Unique的特性直接等於密度=1,滿足Cluster Index所需物理排列特性。
當然NonCluster Index也是密度越低越好!
參考來源:
https://dba.stackexchange.com/questions/96884/clustered-index-on-a-column-with-low-selectivity
Index selectivity - Tomas Lind
When SQL Server evaluates if an index should be used to retrieve data in a query, selectivity is one of the most…tomaslind.netSQL index overview and strategy
November 27, 2018 by A SQL index is used to retrieve data from a database very fast. Indexing a table or view is…www.sqlshack.comSQL Server中的複合叢集索引
是的,每個表只能有一個叢集索引--資料由該索引實際排列,所以您不能有多個叢集索引。 但是我不建議使用複合叢集索引.為什麼?因為叢集索引應該始終是: 儘可能小 - 帶有4位元組的INT是完美的 穩定 …www.366service.com建立複合索引的順序
前晚許志學顧問分享了一個須注意的 primary key 結合 clustered index 的案例。例如多對多關係時,鍵值順序如何? CREATE TABLE A(A1 INT PRIMARY KEY) CREATE TABLE…byronhu.wordpress.comhttps://www.sqlshack.com/designing-effective-sql-server-clustered-indexes/
https://www.ibm.com/developerworks/data/library/tips/dm-0312yip/
http://vito-note.blogspot.com/2013/05/blog-post_5510.html
Share on Twitter Share on FacebookGrafana + Telegraf + InfluxDB 監控 SQL Server - SQL Server
Task Scheduler設定排程錯誤時發送Mail - Powershell
JOIN ON 常數的用途是什麼?跟放在WHERE一樣嗎?/ FULL JOIN要注意的事項- SQL Server
SEO(1) Github(2) Title Tag(2) ML(1) 李宏毅(1) SQL Server(18) Tempdb(1) SSMS(1) Windows(1) 自我成長(2) Excel(1) python Flask(1) python(5) Flask(2)
bart30508 (147)