{"id":4879,"date":"2022-09-29T09:17:56","date_gmt":"2022-09-29T09:17:56","guid":{"rendered":"https:\/\/www.wikitechy.com\/interview-questions\/?p=4879"},"modified":"2022-09-29T09:17:56","modified_gmt":"2022-09-29T09:17:56","slug":"can-you-use-unique-key-as-a-replacement-for-primary-key","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/interview-questions\/sql\/can-you-use-unique-key-as-a-replacement-for-primary-key\/","title":{"rendered":"Can you use UNIQUE KEY as a replacement for Primary Key ?"},"content":{"rendered":"<ul>\n<li style=\"text-align: justify;\">Both Keys are different. For Identifying each and every record in a table we use primary key.<\/li>\n<li style=\"text-align: justify;\">To apply additional uniqueness for other columns on the table we use Unique Key.<\/li>\n<li style=\"text-align: justify;\">Primary Keys are important for a table.<\/li>\n<li style=\"text-align: justify;\">Internal users use Primary Key whereas external users use unique key as it contains some meaningful information.<\/li>\n<li style=\"text-align: justify;\">When uniqueness is needed for multiple columns for a table, we use unique key for all columns and primary keys cannot be used in this case.<\/li>\n<li style=\"text-align: justify;\">Primary key uses clustered index by default and unique key uses Non-clustered index.<\/li>\n<\/ul>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-4880 aligncenter\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/09\/unique-key-as-replacement-for-primary-key.jpg\" alt=\"\" width=\"680\" height=\"352\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/09\/unique-key-as-replacement-for-primary-key.jpg 680w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/09\/unique-key-as-replacement-for-primary-key-300x155.jpg 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/09\/unique-key-as-replacement-for-primary-key-390x202.jpg 390w\" sizes=\"(max-width: 680px) 100vw, 680px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Both Keys are different. For Identifying each and every record in a table we use primary key. To apply additional uniqueness for other columns on the table we use Unique Key. Primary Keys are important for a table. Internal users use Primary Key whereas external users use unique key as it contains some meaningful information. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6547],"tags":[18677,18674,18678,18679,18682,18676,18675,18680,18681],"class_list":["post-4879","post","type-post","status-publish","format-standard","hentry","category-sql","tag-can-we-use-unique-key-as-primary-key","tag-difference-between-primary-key-and-unique-key","tag-difference-between-unique-key-and-primary-key","tag-foreign-key-and-primary-key","tag-how-many-null-values-in-unique-key","tag-primary-key-vs-unique-key","tag-primary-keys-vs-unique-keys","tag-unique-key-example","tag-unique-key-in-sql"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Can you use UNIQUE KEY as a replacement for Primary Key ?<\/title>\n<meta name=\"description\" content=\"Can you use UNIQUE KEY as a replacement for Primary Key ? - No. Both Keys are different. For Identifying each and every record in a table we use primary key.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wikitechy.com\/interview-questions\/sql\/can-you-use-unique-key-as-a-replacement-for-primary-key\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Can you use UNIQUE KEY as a replacement for Primary Key ?\" \/>\n<meta property=\"og:description\" content=\"Can you use UNIQUE KEY as a replacement for Primary Key ? - No. Both Keys are different. For Identifying each and every record in a table we use primary key.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/sql\/can-you-use-unique-key-as-a-replacement-for-primary-key\/\" \/>\n<meta property=\"og:site_name\" content=\"Wikitechy\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-29T09:17:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/09\/unique-key-as-replacement-for-primary-key.jpg\" \/>\n<meta name=\"author\" content=\"webmaster\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"webmaster\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/sql\\\/can-you-use-unique-key-as-a-replacement-for-primary-key\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/sql\\\/can-you-use-unique-key-as-a-replacement-for-primary-key\\\/\"},\"author\":{\"name\":\"webmaster\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#\\\/schema\\\/person\\\/f785ba3ecc599133e65ab6138042a3e4\"},\"headline\":\"Can you use UNIQUE KEY as a replacement for Primary Key ?\",\"datePublished\":\"2022-09-29T09:17:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/sql\\\/can-you-use-unique-key-as-a-replacement-for-primary-key\\\/\"},\"wordCount\":105,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/sql\\\/can-you-use-unique-key-as-a-replacement-for-primary-key\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/wp-content\\\/uploads\\\/2022\\\/09\\\/unique-key-as-replacement-for-primary-key.jpg\",\"keywords\":[\"can we use unique key as primary key\",\"difference between primary key and unique key\",\"difference between unique key and primary key\",\"foreign key and primary key\",\"how many null values in unique key\",\"primary key vs unique key\",\"primary keys vs unique keys\",\"unique key example\",\"unique key in sql\"],\"articleSection\":[\"SQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/sql\\\/can-you-use-unique-key-as-a-replacement-for-primary-key\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/sql\\\/can-you-use-unique-key-as-a-replacement-for-primary-key\\\/\",\"url\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/sql\\\/can-you-use-unique-key-as-a-replacement-for-primary-key\\\/\",\"name\":\"Can you use UNIQUE KEY as a replacement for Primary Key ?\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/sql\\\/can-you-use-unique-key-as-a-replacement-for-primary-key\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/sql\\\/can-you-use-unique-key-as-a-replacement-for-primary-key\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/wp-content\\\/uploads\\\/2022\\\/09\\\/unique-key-as-replacement-for-primary-key.jpg\",\"datePublished\":\"2022-09-29T09:17:56+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#\\\/schema\\\/person\\\/f785ba3ecc599133e65ab6138042a3e4\"},\"description\":\"Can you use UNIQUE KEY as a replacement for Primary Key ? - No. Both Keys are different. For Identifying each and every record in a table we use primary key.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/sql\\\/can-you-use-unique-key-as-a-replacement-for-primary-key\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/sql\\\/can-you-use-unique-key-as-a-replacement-for-primary-key\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/wp-content\\\/uploads\\\/2022\\\/09\\\/unique-key-as-replacement-for-primary-key.jpg\",\"contentUrl\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/wp-content\\\/uploads\\\/2022\\\/09\\\/unique-key-as-replacement-for-primary-key.jpg\",\"width\":680,\"height\":352},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#website\",\"url\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/\",\"name\":\"Wikitechy\",\"description\":\"Interview Questions\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/#\\\/schema\\\/person\\\/f785ba3ecc599133e65ab6138042a3e4\",\"name\":\"webmaster\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g\",\"caption\":\"webmaster\"},\"sameAs\":[\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\"],\"url\":\"https:\\\/\\\/www.wikitechy.com\\\/interview-questions\\\/author\\\/webmaster\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Can you use UNIQUE KEY as a replacement for Primary Key ?","description":"Can you use UNIQUE KEY as a replacement for Primary Key ? - No. Both Keys are different. For Identifying each and every record in a table we use primary key.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wikitechy.com\/interview-questions\/sql\/can-you-use-unique-key-as-a-replacement-for-primary-key\/","og_locale":"en_US","og_type":"article","og_title":"Can you use UNIQUE KEY as a replacement for Primary Key ?","og_description":"Can you use UNIQUE KEY as a replacement for Primary Key ? - No. Both Keys are different. For Identifying each and every record in a table we use primary key.","og_url":"https:\/\/www.wikitechy.com\/interview-questions\/sql\/can-you-use-unique-key-as-a-replacement-for-primary-key\/","og_site_name":"Wikitechy","article_published_time":"2022-09-29T09:17:56+00:00","og_image":[{"url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/09\/unique-key-as-replacement-for-primary-key.jpg","type":"","width":"","height":""}],"author":"webmaster","twitter_card":"summary_large_image","twitter_misc":{"Written by":"webmaster","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.wikitechy.com\/interview-questions\/sql\/can-you-use-unique-key-as-a-replacement-for-primary-key\/#article","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/sql\/can-you-use-unique-key-as-a-replacement-for-primary-key\/"},"author":{"name":"webmaster","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4"},"headline":"Can you use UNIQUE KEY as a replacement for Primary Key ?","datePublished":"2022-09-29T09:17:56+00:00","mainEntityOfPage":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/sql\/can-you-use-unique-key-as-a-replacement-for-primary-key\/"},"wordCount":105,"commentCount":0,"image":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/sql\/can-you-use-unique-key-as-a-replacement-for-primary-key\/#primaryimage"},"thumbnailUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/09\/unique-key-as-replacement-for-primary-key.jpg","keywords":["can we use unique key as primary key","difference between primary key and unique key","difference between unique key and primary key","foreign key and primary key","how many null values in unique key","primary key vs unique key","primary keys vs unique keys","unique key example","unique key in sql"],"articleSection":["SQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.wikitechy.com\/interview-questions\/sql\/can-you-use-unique-key-as-a-replacement-for-primary-key\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.wikitechy.com\/interview-questions\/sql\/can-you-use-unique-key-as-a-replacement-for-primary-key\/","url":"https:\/\/www.wikitechy.com\/interview-questions\/sql\/can-you-use-unique-key-as-a-replacement-for-primary-key\/","name":"Can you use UNIQUE KEY as a replacement for Primary Key ?","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/sql\/can-you-use-unique-key-as-a-replacement-for-primary-key\/#primaryimage"},"image":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/sql\/can-you-use-unique-key-as-a-replacement-for-primary-key\/#primaryimage"},"thumbnailUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/09\/unique-key-as-replacement-for-primary-key.jpg","datePublished":"2022-09-29T09:17:56+00:00","author":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4"},"description":"Can you use UNIQUE KEY as a replacement for Primary Key ? - No. Both Keys are different. For Identifying each and every record in a table we use primary key.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wikitechy.com\/interview-questions\/sql\/can-you-use-unique-key-as-a-replacement-for-primary-key\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/sql\/can-you-use-unique-key-as-a-replacement-for-primary-key\/#primaryimage","url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/09\/unique-key-as-replacement-for-primary-key.jpg","contentUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/09\/unique-key-as-replacement-for-primary-key.jpg","width":680,"height":352},{"@type":"WebSite","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website","url":"https:\/\/www.wikitechy.com\/interview-questions\/","name":"Wikitechy","description":"Interview Questions","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4","name":"webmaster","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g","caption":"webmaster"},"sameAs":["https:\/\/www.wikitechy.com\/interview-questions"],"url":"https:\/\/www.wikitechy.com\/interview-questions\/author\/webmaster\/"}]}},"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4879","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/comments?post=4879"}],"version-history":[{"count":1,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4879\/revisions"}],"predecessor-version":[{"id":4881,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4879\/revisions\/4881"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/media?parent=4879"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/categories?post=4879"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/tags?post=4879"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}