{"id":65,"date":"2023-02-09T19:35:21","date_gmt":"2023-02-09T17:35:21","guid":{"rendered":"http:\/\/130.61.57.200\/?p=65"},"modified":"2023-02-09T19:41:27","modified_gmt":"2023-02-09T17:41:27","slug":"65","status":"publish","type":"post","link":"http:\/\/130.61.57.200\/index.php\/2023\/02\/09\/65\/","title":{"rendered":"Non Clustered Primary Keys in current database"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Creating a Primary Key in SQL Server, by default creates a Clustered Index. The following statement shows all Primary Keys in current database that are using nonclustered indexes instead of clustered. This might not be necessarily wrong, as a clustered key should be chosen on the column that the data is ordered most frequently while the primary key enforces row uniqueness.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>with \npk as (select name ,parent_object_id from sys.objects where type=&#039;PK&#039;),\nut as (select name ,object_id from sys.objects where type=&#039;U&#039;),\nix as (select name,object_id  from sys.indexes where type!=1)\nselect ut.name as &#091;Table], pk.name as &#091;Primary Key] from ut join pk on pk.parent_object_id=ut.object_id join ix on ix.object_id=ut.object_id and ix.object_id=pk.parent_object_id\nwhere ix.name is null<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Creating a Primary Key in SQL Server, by default creates a Clustered Index. The following statement shows all Primary Keys in current database that are using nonclustered indexes instead of clustered. This might not be necessarily wrong, as a clustered key should be chosen on the column that the data is ordered most frequently while [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[25,26,24],"class_list":["post-65","post","type-post","status-publish","format-standard","hentry","category-mssql","tag-clustered-index","tag-nonclustered-index","tag-primary-key"],"blocksy_meta":[],"_links":{"self":[{"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/posts\/65","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/comments?post=65"}],"version-history":[{"count":3,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/posts\/65\/revisions"}],"predecessor-version":[{"id":68,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/posts\/65\/revisions\/68"}],"wp:attachment":[{"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/media?parent=65"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/categories?post=65"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/tags?post=65"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}