{"id":74314,"date":"2019-07-02T11:00:14","date_gmt":"2019-07-02T08:00:14","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=74314"},"modified":"2019-07-01T14:03:40","modified_gmt":"2019-07-01T11:03:40","slug":"sql-primary-key-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/sql-primary-key-example\/","title":{"rendered":"SQL Primary Key Example"},"content":{"rendered":"<p>Welcome readers, in this tutorial, we will understand the SQL Primary Key column that uniquely identifies a tuple in the database table.<\/p>\n<h2>1. Introduction<\/h2>\n<p>SQL <span style=\"text-decoration: underline\">Primary Key<\/span> is a column or multiple columns that uniquely identify a tuple in the database table.<\/p>\n<ul>\n<li>It contains unique values but cannot have null or duplicate<\/li>\n<li>It consists of multiple columns known as a <em>composite primary key<\/em>. In a composite primary key, the values may be duplicated in one column, but the value combination from all columns must be unique<\/li>\n<li>It offers fast access to data<\/li>\n<li>It contains a maximum of 16 columns in MySQL and MariaDB and 32 columns in Oracle<\/li>\n<\/ul>\n<p>To start with this tutorial, we are hoping that users at present have their preferred database installed on their machines. For easy usage, I am using MySQL on a Windows operating system. If someone needs to go through the MySQL installation, please watch <a href=\"https:\/\/www.youtube.com\/watch?v=z1t9m7K6cpI\" target=\"_blank\" rel=\"noopener noreferrer\">this<\/a> video.<\/p>\n<h2>2. SQL Primary Key Example<\/h2>\n<p>Here is a systematic guide and we are using MySQL Database and Workbench.<\/p>\n<h3>2.1 Creating a Primary Key for one column<\/h3>\n<p>The following command creates a table called <code>employees<\/code> having a single column acting as a primary key.<\/p>\n<div>\n<div id=\"highlighter_4689\" class=\"syntaxhighlighter  sql\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<div class=\"line number7 index6 alt2\">7<\/div>\n<div class=\"line number8 index7 alt1\">8<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"sql comments\">\/* Query #1 :: Sql to create primary key for one column *\/<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"sql keyword\">CREATE<\/code> <code class=\"sql keyword\">TABLE<\/code> <code class=\"sql plain\">IF <\/code><code class=\"sql color1\">NOT<\/code> <code class=\"sql plain\">EXISTS employees (<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"sql spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"sql plain\">id <\/code><code class=\"sql keyword\">INT<\/code> <code class=\"sql color1\">NOT<\/code> <code class=\"sql color1\">NULL<\/code><code class=\"sql plain\">,<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"sql spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"sql plain\">firstname <\/code><code class=\"sql keyword\">VARCHAR<\/code><code class=\"sql plain\">(255) <\/code><code class=\"sql color1\">NOT<\/code> <code class=\"sql color1\">NULL<\/code><code class=\"sql plain\">,<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"sql spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"sql plain\">lastname <\/code><code class=\"sql keyword\">VARCHAR<\/code><code class=\"sql plain\">(255) <\/code><code class=\"sql color1\">NULL<\/code><code class=\"sql plain\">,<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"sql spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"sql plain\">age <\/code><code class=\"sql keyword\">INT<\/code> <code class=\"sql color1\">NOT<\/code> <code class=\"sql color1\">NULL<\/code><code class=\"sql plain\">,<\/code><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"sql spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"sql keyword\">PRIMARY<\/code> <code class=\"sql keyword\">KEY<\/code> <code class=\"sql plain\">(id)<\/code><\/div>\n<div class=\"line number8 index7 alt1\"><code class=\"sql plain\">);<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>If everything goes well, the table with a primary key will be created.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"568\" height=\"168\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/Query1-output.jpg\" alt=\"SQL Primary Key\" class=\"wp-image-74315\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/Query1-output.jpg 568w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/Query1-output-300x89.jpg 300w\" sizes=\"(max-width: 568px) 100vw, 568px\" \/><figcaption>Fig. 1: Primary Key<\/figcaption><\/figure>\n<\/div>\n<h3>2.2 Creating a Primary Key for multiple columns<\/h3>\n<p>The following command creates a table called <code>address<\/code> having multiple columns acting as a primary key.<\/p>\n<pre class=\"brush:sql; wrap-lines:false;\">\/* Query #2 :: Sql to create primary key for mulitple columns *\/\nCREATE TABLE IF NOT EXISTS address (\n    id INT NOT NULL,\n    address_1 VARCHAR(255) NOT NULL,\n    address_2 VARCHAR(255) NULL,\n    city VARCHAR(255) NOT NULL,\n    state VARCHAR(255) NOT NULL,\n    country VARCHAR(255) NULL,\n    CONSTRAINT pk_address PRIMARY KEY (id , address_1 , city , state)\n);\n<\/pre>\n<p>If everything goes well, the table with a composite primary key will be created.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"415\" height=\"168\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/Query2-output.jpg\" alt=\"SQL Primary Key - Composite\" class=\"wp-image-74316\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/Query2-output.jpg 415w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/Query2-output-300x121.jpg 300w\" sizes=\"(max-width: 415px) 100vw, 415px\" \/><figcaption>Fig. 2: Composite Primary Key<\/figcaption><\/figure>\n<\/div>\n<h3>2.3 Dropping a Primary Key<\/h3>\n<p>The following command drops the primary key constraint from a table.<\/p>\n<pre class=\"brush:sql; wrap-lines:false;\">\/* Query #3 :: Sql to drop a primary key constraint from the table *\/\nALTER TABLE employees DROP PRIMARY KEY;\n<\/pre>\n<p>If everything goes well, the primary key constraint will be deleted from the table.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"444\" height=\"135\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/Query3-output.jpg\" alt=\"SQL Primary Key - Dropping a Primary Key\" class=\"wp-image-74317\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/Query3-output.jpg 444w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/Query3-output-300x91.jpg 300w\" sizes=\"(max-width: 444px) 100vw, 444px\" \/><figcaption>Fig. 3: Dropping a Primary Key<\/figcaption><\/figure>\n<\/div>\n<h3>2.4 Adding a Primary Key on an existing table<\/h3>\n<p>The following command creates a primary key constraint on an existing table.<\/p>\n<pre class=\"brush:sql; wrap-lines:false;\">\/* Query #4 :: Sql to create a primary key constraint on the existing table *\/\n\/* Note= Primary Key is created on the column or columns defined as not null *\/\nALTER TABLE employees ADD PRIMARY KEY(id);\n<\/pre>\n<p>If everything goes well, the primary key constraint will be added to the existing table.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"568\" height=\"168\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/Query4-output.jpg\" alt=\"SQL Primary Key - add Primary Key\" class=\"wp-image-74318\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/Query4-output.jpg 568w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/06\/Query4-output-300x89.jpg 300w\" sizes=\"(max-width: 568px) 100vw, 568px\" \/><figcaption>Fig. 4: Altering table to add Primary Key<\/figcaption><\/figure>\n<\/div>\n<p>Developers can follow the same approach to create a <em>primary key constraint on multiple columns<\/em> of an existing table.<\/p>\n<div>\n<div id=\"highlighter_568767\" class=\"syntaxhighlighter  sql\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"sql comments\">\/* Query #5 :: Sql to create a primary key constraint on multiple columns of an existing table *\/<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"sql comments\">\/* Note= Primary Key is created on the column or columns defined as not null *\/<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"sql keyword\">ALTER<\/code> <code class=\"sql keyword\">TABLE<\/code> <code class=\"sql plain\">address <\/code><code class=\"sql keyword\">ADD<\/code> <code class=\"sql keyword\">PRIMARY<\/code> <code class=\"sql keyword\">KEY<\/code> <code class=\"sql plain\">(id , address_1 , city , state);<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>That is all for this tutorial and I hope the article served you whatever you were looking for. Happy Learning and do not forget to share!<\/p>\n<h2>3. Conclusion<\/h2>\n<p>In this section, developers learned how to create a Primary Key in a database table. Developers can download the sample scripts in the <a href=\"#projectDownload\">Downloads<\/a> section.<\/p>\n<h2><a name=\"projectDownload\"><\/a>4. Download the SQL Script<\/h2>\n<p>This was an example of creating a Primary Key in a database table.<\/p>\n<ul>\n<li>Each tuple in a table can have only one primary key<\/li>\n<li>It contains unique values but cannot have null or duplicate<\/li>\n<li>A primary key column will throw an error while inserting a duplicate value<\/li>\n<li>A non-primary key column can have a duplicate value<\/li>\n<\/ul>\n<div class=\"download\"><strong>Download<\/strong><br \/>You can download the full source code of this example here: <a target=\"_blank\" href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/07\/Sql_Primary-key-tutorial.zip\" rel=\"noopener noreferrer\"><strong>SQL Primary Key Example<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Welcome readers, in this tutorial, we will understand the SQL Primary Key column that uniquely identifies a tuple in the database table. 1. Introduction SQL Primary Key is a column or multiple columns that uniquely identify a tuple in the database table. It contains unique values but cannot have null or duplicate It consists of &hellip;<\/p>\n","protected":false},"author":119,"featured_media":1204,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53],"tags":[881,647,1055],"class_list":["post-74314","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sql","tag-database","tag-mysql","tag-sql"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SQL Primary Key Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Interested to learn more about SQL? Then check out our detailed example on SQL 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:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/sql-primary-key-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Primary Key Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Interested to learn more about SQL? Then check out our detailed example on SQL Primary Key!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/sql-primary-key-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2019-07-02T08:00:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Yatin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Yatin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/sql-primary-key-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/sql-primary-key-example\/\"},\"author\":{\"name\":\"Yatin\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13\"},\"headline\":\"SQL Primary Key Example\",\"datePublished\":\"2019-07-02T08:00:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/sql-primary-key-example\/\"},\"wordCount\":473,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/sql-primary-key-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"keywords\":[\"database\",\"mysql\",\"sql\"],\"articleSection\":[\"sql\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/sql-primary-key-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/sql-primary-key-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/sql-primary-key-example\/\",\"name\":\"SQL Primary Key Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/sql-primary-key-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/sql-primary-key-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"datePublished\":\"2019-07-02T08:00:14+00:00\",\"description\":\"Interested to learn more about SQL? Then check out our detailed example on SQL Primary Key!\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/sql-primary-key-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/sql-primary-key-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/sql-primary-key-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"Bipartite Graph\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/sql-primary-key-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"sql\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/sql\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"SQL Primary Key Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13\",\"name\":\"Yatin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg\",\"caption\":\"Yatin\"},\"description\":\"An experience full-stack engineer well versed with Core Java, Spring\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).\",\"sameAs\":[\"https:\/\/www.javacodegeeks.com\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/yatin-batra\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQL Primary Key Example - Java Code Geeks","description":"Interested to learn more about SQL? Then check out our detailed example on SQL 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:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/sql-primary-key-example\/","og_locale":"en_US","og_type":"article","og_title":"SQL Primary Key Example - Java Code Geeks","og_description":"Interested to learn more about SQL? Then check out our detailed example on SQL Primary Key!","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/sql-primary-key-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2019-07-02T08:00:14+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","type":"image\/jpeg"}],"author":"Yatin","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Yatin","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/sql-primary-key-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/sql-primary-key-example\/"},"author":{"name":"Yatin","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13"},"headline":"SQL Primary Key Example","datePublished":"2019-07-02T08:00:14+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/sql-primary-key-example\/"},"wordCount":473,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/sql-primary-key-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","keywords":["database","mysql","sql"],"articleSection":["sql"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/sql-primary-key-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/sql-primary-key-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/sql-primary-key-example\/","name":"SQL Primary Key Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/sql-primary-key-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/sql-primary-key-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","datePublished":"2019-07-02T08:00:14+00:00","description":"Interested to learn more about SQL? Then check out our detailed example on SQL Primary Key!","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/sql-primary-key-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/sql-primary-key-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/sql-primary-key-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","width":150,"height":150,"caption":"Bipartite Graph"},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/sql-primary-key-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/"},{"@type":"ListItem","position":4,"name":"sql","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/sql\/"},{"@type":"ListItem","position":5,"name":"SQL Primary Key Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13","name":"Yatin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg","caption":"Yatin"},"description":"An experience full-stack engineer well versed with Core Java, Spring\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).","sameAs":["https:\/\/www.javacodegeeks.com"],"url":"https:\/\/examples.javacodegeeks.com\/author\/yatin-batra\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/74314","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/119"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=74314"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/74314\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1204"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=74314"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=74314"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=74314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}