{"id":5785,"date":"2021-04-01T12:37:37","date_gmt":"2021-04-01T12:37:37","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/?p=5785"},"modified":"2021-04-01T12:39:25","modified_gmt":"2021-04-01T12:39:25","slug":"creating-a-table-using-my-sql-queries","status":"publish","type":"post","link":"https:\/\/www.scmgalaxy.com\/tutorials\/creating-a-table-using-my-sql-queries\/","title":{"rendered":"Creating a Table using MySql queries:"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">In this we will learn how we can create tables in the database using sql queries. As we know it becomes quite complicated to make the tables manually in the database. To ease the process we can follow the steps to make tables using my sql queries.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE table_name (\n    column1 column1 datatype column1 constraint,\n    column2 column2 datatype column2 constraint,\n    column3 column3 datatype column3 constraint,\n   ....\n);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Constraints:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>NOT NULL CONSTRAINT<\/strong> &#8211; Ensures that a column cannot have a null value.<\/li><li><strong>DEFAULT CONSTRAINT<\/strong> &#8211; Provides a default value for a column when none is specified.<\/li><li><strong>UNIQUE CONSTRAINT<\/strong> &#8211; Ensures that all value in a column are different.<\/li><li><strong>CHECK CONSTRAINT <\/strong>&#8211; Make sure all values in a column satisfy certian criteria.<\/li><li><strong>PRIMARY_KEY CONSTRAINT <\/strong>&#8211; Used to uniquely identify a row in a table.<\/li><li><strong>FOREIGN_KEY CONSTRAINT <\/strong>&#8211; Used to ensure referential integrity of the data.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Keys:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>A primary key is used to uniquely identify each row in a table.<\/li><li>A primary key can consists of one or more columns on a table.<\/li><li>When multiple columns are used as primary key, it is called as Composite key.<\/li><li>A foreign key is a column (or columns) that references a column (most often primary key) of other table.<\/li><li>The purpose of foreign key is to referential integrity of the data.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"904\" height=\"362\" src=\"https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2021\/04\/Untitled-1.jpg\" alt=\"\" class=\"wp-image-5786\" srcset=\"https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2021\/04\/Untitled-1.jpg 904w, https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2021\/04\/Untitled-1-300x120.jpg 300w, https:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2021\/04\/Untitled-1-768x308.jpg 768w\" sizes=\"auto, (max-width: 904px) 100vw, 904px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">As shown in the above picture, Cust_ID is the foreign key for order table whereas it is primary key for in the Customer table that means the value of Cust_ID will not change in either of the table.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example we will create a table named as customer_table inside the &#8216;test&#8217; database:<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/Joydeep-cotocus\/f9cd72fcba465481909e066d538a3eb2.js\"><\/script>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this we will learn how we can create tables in the database using sql queries. As we know it [&hellip;]<\/p>\n","protected":false},"author":20,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[72],"tags":[3619,493,5185],"class_list":["post-5785","post","type-post","status-publish","format-standard","hentry","category-database","tag-databases","tag-mysql","tag-query"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Creating a Table using MySql queries: - scmGalaxy<\/title>\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.scmgalaxy.com\/tutorials\/creating-a-table-using-my-sql-queries\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Creating a Table using MySql queries: - scmGalaxy\" \/>\n<meta property=\"og:description\" content=\"In this we will learn how we can create tables in the database using sql queries. As we know it [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.scmgalaxy.com\/tutorials\/creating-a-table-using-my-sql-queries\/\" \/>\n<meta property=\"og:site_name\" content=\"scmGalaxy\" \/>\n<meta property=\"article:published_time\" content=\"2021-04-01T12:37:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-04-01T12:39:25+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2021\/04\/Untitled-1.jpg\" \/>\n<meta name=\"author\" content=\"Joydeep M\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Joydeep M\" \/>\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.scmgalaxy.com\\\/tutorials\\\/creating-a-table-using-my-sql-queries\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/creating-a-table-using-my-sql-queries\\\/\"},\"author\":{\"name\":\"Joydeep M\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/8a2c0533775223a96dd307662111bac6\"},\"headline\":\"Creating a Table using MySql queries:\",\"datePublished\":\"2021-04-01T12:37:37+00:00\",\"dateModified\":\"2021-04-01T12:39:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/creating-a-table-using-my-sql-queries\\\/\"},\"wordCount\":259,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/creating-a-table-using-my-sql-queries\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/Untitled-1.jpg\",\"keywords\":[\"Databases\",\"mysql\",\"query\"],\"articleSection\":[\"Database\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/creating-a-table-using-my-sql-queries\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/creating-a-table-using-my-sql-queries\\\/\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/creating-a-table-using-my-sql-queries\\\/\",\"name\":\"Creating a Table using MySql queries: - scmGalaxy\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/creating-a-table-using-my-sql-queries\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/creating-a-table-using-my-sql-queries\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/Untitled-1.jpg\",\"datePublished\":\"2021-04-01T12:37:37+00:00\",\"dateModified\":\"2021-04-01T12:39:25+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/8a2c0533775223a96dd307662111bac6\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/creating-a-table-using-my-sql-queries\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/creating-a-table-using-my-sql-queries\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/creating-a-table-using-my-sql-queries\\\/#primaryimage\",\"url\":\"http:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/Untitled-1.jpg\",\"contentUrl\":\"http:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/Untitled-1.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/creating-a-table-using-my-sql-queries\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Creating a Table using MySql queries:\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#website\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/\",\"name\":\"scmGalaxy\",\"description\":\"A Platform for Software Engineers\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/8a2c0533775223a96dd307662111bac6\",\"name\":\"Joydeep M\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/fb490db5d492c960456cc628f9e832fda72c5bc426cd8a13b18cbb95bca7ce99?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/fb490db5d492c960456cc628f9e832fda72c5bc426cd8a13b18cbb95bca7ce99?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/fb490db5d492c960456cc628f9e832fda72c5bc426cd8a13b18cbb95bca7ce99?s=96&d=mm&r=g\",\"caption\":\"Joydeep M\"},\"description\":\"An investment in knowledge pays the best interest.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/joydeep-kumar-538412208\\\/\"],\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/author\\\/joydeep\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Creating a Table using MySql queries: - scmGalaxy","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.scmgalaxy.com\/tutorials\/creating-a-table-using-my-sql-queries\/","og_locale":"en_US","og_type":"article","og_title":"Creating a Table using MySql queries: - scmGalaxy","og_description":"In this we will learn how we can create tables in the database using sql queries. As we know it [&hellip;]","og_url":"https:\/\/www.scmgalaxy.com\/tutorials\/creating-a-table-using-my-sql-queries\/","og_site_name":"scmGalaxy","article_published_time":"2021-04-01T12:37:37+00:00","article_modified_time":"2021-04-01T12:39:25+00:00","og_image":[{"url":"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2021\/04\/Untitled-1.jpg","type":"","width":"","height":""}],"author":"Joydeep M","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Joydeep M","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/creating-a-table-using-my-sql-queries\/#article","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/creating-a-table-using-my-sql-queries\/"},"author":{"name":"Joydeep M","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/8a2c0533775223a96dd307662111bac6"},"headline":"Creating a Table using MySql queries:","datePublished":"2021-04-01T12:37:37+00:00","dateModified":"2021-04-01T12:39:25+00:00","mainEntityOfPage":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/creating-a-table-using-my-sql-queries\/"},"wordCount":259,"commentCount":0,"image":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/creating-a-table-using-my-sql-queries\/#primaryimage"},"thumbnailUrl":"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2021\/04\/Untitled-1.jpg","keywords":["Databases","mysql","query"],"articleSection":["Database"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.scmgalaxy.com\/tutorials\/creating-a-table-using-my-sql-queries\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/creating-a-table-using-my-sql-queries\/","url":"https:\/\/www.scmgalaxy.com\/tutorials\/creating-a-table-using-my-sql-queries\/","name":"Creating a Table using MySql queries: - scmGalaxy","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/creating-a-table-using-my-sql-queries\/#primaryimage"},"image":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/creating-a-table-using-my-sql-queries\/#primaryimage"},"thumbnailUrl":"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2021\/04\/Untitled-1.jpg","datePublished":"2021-04-01T12:37:37+00:00","dateModified":"2021-04-01T12:39:25+00:00","author":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/8a2c0533775223a96dd307662111bac6"},"breadcrumb":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/creating-a-table-using-my-sql-queries\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.scmgalaxy.com\/tutorials\/creating-a-table-using-my-sql-queries\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/creating-a-table-using-my-sql-queries\/#primaryimage","url":"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2021\/04\/Untitled-1.jpg","contentUrl":"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2021\/04\/Untitled-1.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/creating-a-table-using-my-sql-queries\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.scmgalaxy.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Creating a Table using MySql queries:"}]},{"@type":"WebSite","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#website","url":"https:\/\/www.scmgalaxy.com\/tutorials\/","name":"scmGalaxy","description":"A Platform for Software Engineers","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.scmgalaxy.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/8a2c0533775223a96dd307662111bac6","name":"Joydeep M","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/fb490db5d492c960456cc628f9e832fda72c5bc426cd8a13b18cbb95bca7ce99?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/fb490db5d492c960456cc628f9e832fda72c5bc426cd8a13b18cbb95bca7ce99?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/fb490db5d492c960456cc628f9e832fda72c5bc426cd8a13b18cbb95bca7ce99?s=96&d=mm&r=g","caption":"Joydeep M"},"description":"An investment in knowledge pays the best interest.","sameAs":["https:\/\/www.linkedin.com\/in\/joydeep-kumar-538412208\/"],"url":"https:\/\/www.scmgalaxy.com\/tutorials\/author\/joydeep\/"}]}},"_links":{"self":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/5785","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/users\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/comments?post=5785"}],"version-history":[{"count":2,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/5785\/revisions"}],"predecessor-version":[{"id":5788,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/5785\/revisions\/5788"}],"wp:attachment":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/media?parent=5785"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/categories?post=5785"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/tags?post=5785"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}