{"id":290,"date":"2018-12-13T08:11:49","date_gmt":"2018-12-13T08:11:49","guid":{"rendered":"https:\/\/barkhane.com\/sql\/2018\/12\/13\/sql-keys\/"},"modified":"2024-03-03T17:54:05","modified_gmt":"2024-03-03T17:54:05","slug":"sql-keys","status":"publish","type":"post","link":"https:\/\/barkhane.com\/sql\/sql-keys\/","title":{"rendered":"SQL Keys"},"content":{"rendered":"<p>A key is a single or combination of multiple fields in a table. Its is used to fetch or retrieve records\/data-rows from data table according to the condition\/requirement. Keys are also used to create relationship among different database tables or views.<\/p>\n<p>&nbsp;<\/p>\n<h2>Types of SQL Keys<\/h2>\n<p>We have following types of keys in SQL which are used to fetch records from tables and to make relationship among tables or views.<\/p>\n<ol class=\"orderlist\">\n<li>\n<h2>Super Key<\/h2>\n<p>Super key is a set of one or more than one keys that can be used to identify a record uniquely in a table.<b>Example :<\/b>\u00a0Primary key, Unique key, Alternate key are subset of Super Keys.<\/li>\n<li>\n<h2>Candidate Key<\/h2>\n<p>A Candidate Key is a set of one or more fields\/columns that can identify a record uniquely in a table. There can be multiple Candidate Keys in one table. Each Candidate Key can work as Primary Key.<\/p>\n<p>&nbsp;<\/li>\n<li>\n<h2>Primary Key<\/h2>\n<p>Primary key is a set of one or more fields\/columns of a table that uniquely identify a record in database table. It can not accept null, duplicate values. Only one Candidate Key can be Primary Key.<\/li>\n<li>\n<h2>Alternate key<\/h2>\n<p>A Alternate key is a key that can be work as a primary key. Basically it is a candidate key that currently is not primary key.<\/li>\n<li>\n<h2>Composite\/Compound Key<\/h2>\n<p>Composite Key is a combination of more than one fields\/columns of a table. It can be a Candidate key, Primary key.<\/li>\n<li>\n<h2>Unique Key<\/h2>\n<p>Uniquekey is a set of one or more fields\/columns of a table that uniquely identify a record in database table. It is like Primary key but it can accept only one null value and it can not have duplicate values.<\/li>\n<li>\n<h2>Foreign Key<\/h2>\n<p>Foreign Key is a field in database table that is Primary key in another table. It can accept multiple null, duplicate values.<\/p>\n<p><b>Example :<\/b>\u00a0We can have a DeptID column in the Employee table which is pointing to DeptID column in a department table where it a primary key.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>A key is a single or combination of multiple fields in a table. Its is used to fetch or retrieve [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[2],"tags":[],"class_list":["post-290","post","type-post","status-publish","format-standard","hentry","category-sql"],"_links":{"self":[{"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/posts\/290","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/comments?post=290"}],"version-history":[{"count":0,"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/posts\/290\/revisions"}],"wp:attachment":[{"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/media?parent=290"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/categories?post=290"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/tags?post=290"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}