{"id":1396,"date":"2019-12-12T12:31:28","date_gmt":"2019-12-12T01:31:28","guid":{"rendered":"https:\/\/www.dynamicwebtraining.com.au\/blog\/?p=1396"},"modified":"2024-11-14T13:49:39","modified_gmt":"2024-11-14T02:49:39","slug":"create-sql-table-and-insert-data","status":"publish","type":"post","link":"https:\/\/www.dynamicwebtraining.com.au\/blog\/create-sql-table-and-insert-data","title":{"rendered":"How to Create a Table and Insert Data in SQL"},"content":{"rendered":"\n<p>If you know one or two things in about using a computer, you definitely might have heard about the term SQL. But maybe you don\u2019t know what that is, and you have never bothered to understand it. Well, this is not rocket science, especially for you, but a person who is utterly green about technology it probably is. So first of all, what is the meaning of SQL? TO start with the initials SQL stand for Structured Query Language.<\/p>\n\n\n\n<br>\n\n\n\n<!--more-->\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"536\" src=\"https:\/\/www.dynamicwebtraining.com.au\/blog\/wp-content\/uploads\/2019\/12\/how-to-create-a-table-and-insert-data-in-sql-feature-1024x536.jpg\" alt=\"Create a Table and Insert Data - Dynamic Web Training\" class=\"wp-image-1400\" srcset=\"https:\/\/www.dynamicwebtraining.com.au\/blog\/wp-content\/uploads\/2019\/12\/how-to-create-a-table-and-insert-data-in-sql-feature-1024x536.jpg 1024w, https:\/\/www.dynamicwebtraining.com.au\/blog\/wp-content\/uploads\/2019\/12\/how-to-create-a-table-and-insert-data-in-sql-feature-300x157.jpg 300w, https:\/\/www.dynamicwebtraining.com.au\/blog\/wp-content\/uploads\/2019\/12\/how-to-create-a-table-and-insert-data-in-sql-feature.jpg 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<br>\n\n\n\n<p>A not so detailed definition of SQL is that this is what is used when communicating to a database. Again, what is a database? A database is an electronic system where one can easily access data. Not only it obtains the data, but also the user can also manipulate it as well as update it. Enterprises use databases to store, manage, and retrieve information.<\/p>\n\n\n\n<p>The new-age database is maintained by what we know as a DBMS, which stands for the database management system. Examples of databases comprise of Microsoft Access, FileMaker, FoxPro, Oracle, Clipper, dBASE, RDBMS, PostgreSQL, MySQL, and SQL Server. The simplest definition of what a database is a gathering of information, professionally called data, which is stored in a server.<\/p>\n\n\n\n<p>Therefore SQL, according to the American National Standards Institute, ANSI, and SQL, is the standard language for the database management system to relate. An SQL statement is used to undertake tasks like updating the data on the existing database, retrieving that data from the database and equally, managing it.<\/p>\n\n\n\n<br>\n\n\n\n<h2 class=\"wp-block-heading\">Application of SQL<\/h2>\n\n\n\n<p>As said earlier, SQL has many uses, including data integration script, analytical queries, retrieving information, and so many other applications.<\/p>\n\n\n\n<br>\n\n\n\n<h4 class=\"wp-block-heading\">Data integration script<\/h4>\n\n\n\n<p>SQL is used to write data integration scripts by a database administrator or a developer<\/p>\n\n\n\n<br>\n\n\n\n<h4 class=\"wp-block-heading\">Analytical queries<\/h4>\n\n\n\n<p>Data analysts use structured question language for setting as well as running analytical questions all the time.<\/p>\n\n\n\n<br>\n\n\n\n<h4 class=\"wp-block-heading\">Retrieve data<\/h4>\n\n\n\n<p>A database administrator uses SQL to retrieve a subset of the data within a database for analytics application and also processing transactions. Commonly used SQL elements include insert, select, delete, add, create, alter, and truncate.<\/p>\n\n\n\n<br>\n\n\n\n<h4 class=\"wp-block-heading\">Important SQL applications<\/h4>\n\n\n\n<p>SQL modifies the index structures as well as a database table. Also, the administrator can add, delete, and update the rows of the information using SQL.<\/p>\n\n\n\n<br>\n\n\n\n<h3 class=\"wp-block-heading\">Benefits of SQL<\/h3>\n\n\n\n<p>There is a myriad of benefits of why one should use SQL here are just a few reasons and benefits.<\/p>\n\n\n\n<br>\n\n\n\n<h4 class=\"wp-block-heading\">SQL Standard<\/h4>\n\n\n\n<p>The first standard for this language was developed in 1986; the International National Standards followed suite in 1987. Today we use the latest standard that was established in 2011.<\/p>\n\n\n\n<br>\n\n\n\n<h4 class=\"wp-block-heading\">Portable<\/h4>\n\n\n\n<p>It runs on PCs, mainframes, servers, and mobile devices. This language also runs in local systems, the internet, and the intranet. SQL databases can be comfortably moved from a system to another without any compilations.<\/p>\n\n\n\n<br>\n\n\n\n<h4 class=\"wp-block-heading\">Open Source<\/h4>\n\n\n\n<p>SQL is open source, meaning that you can use it at a low cost with large communities.<\/p>\n\n\n\n<br>\n\n\n\n<h4 class=\"wp-block-heading\">It is easy to learn and use<\/h4>\n\n\n\n<p>This language consists of English statements, meaning that you can quickly learn and use it. Writing an SQL query has never been easier.<\/p>\n\n\n\n<br>\n\n\n\n<h4 class=\"wp-block-heading\">It is a high-value skill to have<\/h4>\n\n\n\n<p>Many jobs such as IT support, business data analysis, and web development require a candidate who is good at SQL. It is the reason we want to teach you how you can create a table and insert data in the Structured Query Language.<\/p>\n\n\n\n<br>\n\n\n\n<h3 class=\"wp-block-heading\">Creating a Table in SQL and Inserting DATA<\/h3>\n\n\n\n<br>\n\n\n\n<p>First of all, there are various ways of creating tables and inserting data in SQL. To start with,<\/p>\n\n\n\n<br>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>One can create a table using the create statement; for instance, you want to create a table titled pupils. Use the syntax below.<\/strong><\/p>\n<\/blockquote>\n\n\n\n<br>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE PUPILS (\n  Pupilid int IDENTITY (1.1) NOT NULL, \n  Firstname varchar (200), \n  Lastname varchar (200), \n  Email varchar (100)\n)<\/code><\/pre>\n\n\n\n<br>\n\n\n\n<p>Therefore, this syntax will get you the table Pupil, where the pupil id is not null. If you want to insert the data into that table titled \u2018Pupil\u2019 here is what you do using the first method.<\/p>\n\n\n\n<br>\n\n\n\n<pre class=\"wp-block-code\"><code>Insert into Pupils, \n(\n  Pupilid, Firstname, Lastname, email\n) \nValues \n  (\n    1, \u2019Watson\u2019, \u2019Keter, \u2019\u2019 Watsonketer@gmail.com\u2019\n  )<\/code><\/pre>\n\n\n\n<br>\n\n\n\n<p>You can verify this query to get the following result<\/p>\n\n\n\n<br>\n\n\n\n<figure class=\"wp-block-table is-style-stripes block-editor-block-card__description\"><table><thead><tr><th>Student ID<\/th><th>First Name<\/th><th>Last Name<\/th><th>Email<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>Watson<\/td><td>Keter<\/td><td>watsonketer@gmail.com<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<br>\n\n\n\n<p>The second method is how you can insert values into the table using a different table. See below.<\/p>\n\n\n\n<p>For instance, we already have a table named Pupils, and here we want to insert the table\u2019s values into the other table called Pupildemo.<\/p>\n\n\n\n<br>\n\n\n\n<h4 class=\"wp-block-heading\">Create table \u2018Pupildemo\u2019<\/h4>\n\n\n\n<br>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE Pupildemo (\n  Pupilid int IDENTITY (1.1) NOT NULL, \n  Firstname varchar (200), \n  Lastname varchar (200), \n  Email varchar (100)\n)<\/code><\/pre>\n\n\n\n<br>\n\n\n\n<p>At this juncture, to insert data of table \u2018Pupils\u2019 into the table \u2018Pupildemo\u2019, you can use the following statement.<\/p>\n\n\n\n<br>\n\n\n\n<pre class=\"wp-block-code\"><code>Insert into Pupildemo (\n  Pupilid, Firstname, Lastname, email\n) Then, \nSELECT \n  Pupilid, \n  Firstname, \n  Lastname, \n  email \nfrom \n  Pupils\n<\/code><\/pre>\n\n\n\n<br>\n\n\n\n<p>You can verify this statement results to get the results using this method.<\/p>\n\n\n\n<br>\n\n\n\n<p>SELECT, FROM Pupildemo, and you will get this result.<\/p>\n\n\n\n<br>\n\n\n\n<figure class=\"wp-block-table is-style-stripes block-editor-block-card__description\"><table><thead><tr><th>Student ID<\/th><th>First Name<\/th><th>Last Name<\/th><th>Email<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>Watson<\/td><td>Keter<\/td><td>watsonketer@gmail.com<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<br>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><em><strong>Note<\/strong><\/em>: For you to insert the data on one table to the other, the data type of the column needs to be the same. <\/p>\n<\/blockquote>\n\n\n\n<br>\n\n\n\n<h4 class=\"wp-block-heading\">Rename the current table<\/h4>\n\n\n\n<br>\n\n\n\n<p>Alter the name of \u2018Pupildemo\u2019 table to Pupilscopy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ALTER TABLE \n  Pupildemo RENAME TO Pupilscopy\n<\/code><\/pre>\n\n\n\n<br>\n\n\n\n<p><em>Consider the table \u2018Pupils\u2019 that is given down here, and ADD column \u2018Phone\u2019 in that table.<\/em><\/p>\n\n\n\n<br>\n\n\n\n<figure class=\"wp-block-table is-style-stripes block-editor-block-card__description\"><table><thead><tr><th>Student ID<\/th><th>First Name<\/th><th>Last Name<\/th><th>Email<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>Watson<\/td><td>Keter<\/td><td>watsonketer@gmail.com<\/td><\/tr><tr><td>2<\/td><td>Kimberly<\/td><td>Jones<\/td><td>kimjones@gmail.com<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<br>\n\n\n\n<p> Here, you are required to use the ALTER TABLE command to add a column to the existing table.<\/p>\n\n\n\n<br>\n\n\n\n<p>Here is what happens<\/p>\n\n\n\n<br>\n\n\n\n<pre class=\"wp-block-code\"><code>ALTER TABLE \n  Pupils, \n  then, \nADD \n  Phone INT Null\n<\/code><\/pre>\n\n\n\n<br>\n\n\n\n<p>This is what you get<\/p>\n\n\n\n<br>\n\n\n\n<figure class=\"wp-block-table is-style-stripes block-editor-block-card__description\"><table><thead><tr><th>Student ID<\/th><th>First Name<\/th><th>Last Name<\/th><th>Email<\/th><th>Phone<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>Watson<\/td><td>Keter<\/td><td>watsonketer@gmail.com<\/td><td>Null<\/td><\/tr><tr><td>2<\/td><td>Kimberly<\/td><td>Jones<\/td><td>kimjones@gmail.com<\/td><td>Null<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<br>\n\n\n\n<p><strong>Please Note &#8211; <\/strong><br>If you use the ALTER TABLE statement to add another column to the existing table, and don\u2019t add values, you get a default Null on those columns. It is why the phone row has Null since we did not add any phone data.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you know one or two things in about using a computer, you definitely might have heard about the term SQL. But maybe you don\u2019t know what that is, and you have never bothered to understand it. Well, this is not rocket science, especially for you, but a person who is utterly green about technology&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1621],"tags":[],"class_list":["post-1396","post","type-post","status-publish","format-standard","hentry","category-programming"],"yoast_head":"<title>Learn to write SQL Query to create a table and insert data<\/title>\n<meta name=\"description\" content=\"View and Share Dynamic Web Training Blog Archives. This is a great source of articles and posts on Computer and IT training, tutorials and insights\" \/>\n<meta name=\"robots\" content=\"index, follow\" \/>\n<meta name=\"googlebot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta name=\"bingbot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dynamicwebtraining.com.au\/blog\/create-sql-table-and-insert-data\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Learn to write SQL Query to create a table and insert data\" \/>\n<meta property=\"og:description\" content=\"Learn to write an efficient SQL statement to perform tasks such as updating data to the existing database, retrieving and managing data from the database.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dynamicwebtraining.com.au\/blog\/create-sql-table-and-insert-data\" \/>\n<meta property=\"og:site_name\" content=\"Dynamic Web Training Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DynamicWebTraining\/\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/DynamicWebTraining\/\" \/>\n<meta property=\"article:published_time\" content=\"2019-12-12T01:31:28+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-14T02:49:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.dynamicwebtraining.com.au\/blog\/wp-content\/uploads\/2019\/12\/how-to-create-a-table-and-insert-data-in-sql-feature-1024x536.jpg\" \/>\n<meta name=\"twitter:card\" content=\"summary\" \/>\n<meta name=\"twitter:creator\" content=\"@dynamicwebtrain\" \/>\n<meta name=\"twitter:site\" content=\"@dynamicwebtrain\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.dynamicwebtraining.com.au\/blog\/#organization\",\"name\":\"Dynamic Web Training\",\"url\":\"https:\/\/www.dynamicwebtraining.com.au\/blog\/\",\"sameAs\":[\"https:\/\/www.facebook.com\/DynamicWebTraining\/\",\"https:\/\/www.linkedin.com\/company\/dynamic-web-training\",\"https:\/\/twitter.com\/dynamicwebtrain\"],\"logo\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.dynamicwebtraining.com.au\/blog\/#logo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/www.dynamicwebtraining.com.au\/blog\/wp-content\/uploads\/2016\/02\/logo.png\",\"width\":361,\"height\":109,\"caption\":\"Dynamic Web Training\"},\"image\":{\"@id\":\"https:\/\/www.dynamicwebtraining.com.au\/blog\/#logo\"}},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dynamicwebtraining.com.au\/blog\/#website\",\"url\":\"https:\/\/www.dynamicwebtraining.com.au\/blog\/\",\"name\":\"Dynamic Web Training Blog\",\"description\":\"The Ultimate Training Experience.\",\"publisher\":{\"@id\":\"https:\/\/www.dynamicwebtraining.com.au\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/www.dynamicwebtraining.com.au\/blog\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.dynamicwebtraining.com.au\/blog\/create-sql-table-and-insert-data#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/www.dynamicwebtraining.com.au\/blog\/wp-content\/uploads\/2019\/12\/how-to-create-a-table-and-insert-data-in-sql-feature.jpg\",\"width\":1200,\"height\":628},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dynamicwebtraining.com.au\/blog\/create-sql-table-and-insert-data#webpage\",\"url\":\"https:\/\/www.dynamicwebtraining.com.au\/blog\/create-sql-table-and-insert-data\",\"name\":\"Learn to write SQL Query to create a table and insert data\",\"isPartOf\":{\"@id\":\"https:\/\/www.dynamicwebtraining.com.au\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.dynamicwebtraining.com.au\/blog\/create-sql-table-and-insert-data#primaryimage\"},\"datePublished\":\"2019-12-12T01:31:28+00:00\",\"dateModified\":\"2024-11-14T02:49:39+00:00\",\"description\":\"Learn to write an efficient SQL statement to perform tasks such as updating data to the existing database, retrieving and managing data from the database.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.dynamicwebtraining.com.au\/blog\/create-sql-table-and-insert-data#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dynamicwebtraining.com.au\/blog\/create-sql-table-and-insert-data\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dynamicwebtraining.com.au\/blog\/create-sql-table-and-insert-data#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dynamicwebtraining.com.au\/blog\",\"url\":\"https:\/\/www.dynamicwebtraining.com.au\/blog\",\"name\":\"Training Blog\"}},{\"@type\":\"ListItem\",\"position\":2,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dynamicwebtraining.com.au\/blog\/category\/programming\",\"url\":\"https:\/\/www.dynamicwebtraining.com.au\/blog\/category\/programming\",\"name\":\"Programming\"}},{\"@type\":\"ListItem\",\"position\":3,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dynamicwebtraining.com.au\/blog\/create-sql-table-and-insert-data\",\"url\":\"https:\/\/www.dynamicwebtraining.com.au\/blog\/create-sql-table-and-insert-data\",\"name\":\"How to Create a Table and Insert Data in SQL\"}}]},{\"@type\":\"Article\",\"@id\":\"https:\/\/www.dynamicwebtraining.com.au\/blog\/create-sql-table-and-insert-data#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dynamicwebtraining.com.au\/blog\/create-sql-table-and-insert-data#webpage\"},\"author\":{\"@id\":\"https:\/\/www.dynamicwebtraining.com.au\/blog\/#\/schema\/person\/c94653aed4a6decc8e357af0a1082233\"},\"headline\":\"How to Create a Table and Insert Data in SQL\",\"datePublished\":\"2019-12-12T01:31:28+00:00\",\"dateModified\":\"2024-11-14T02:49:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dynamicwebtraining.com.au\/blog\/create-sql-table-and-insert-data#webpage\"},\"publisher\":{\"@id\":\"https:\/\/www.dynamicwebtraining.com.au\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.dynamicwebtraining.com.au\/blog\/create-sql-table-and-insert-data#primaryimage\"},\"articleSection\":\"Programming\",\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.dynamicwebtraining.com.au\/blog\/#\/schema\/person\/c94653aed4a6decc8e357af0a1082233\",\"name\":\"Dynamic Web Training\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.dynamicwebtraining.com.au\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/0a14e92e62ad4eee0843f5cf7da3a00e1df4c9763922d4d20ba3ed2402a6896d?s=96&d=mm&r=g\",\"caption\":\"Dynamic Web Training\"},\"description\":\"Dynamic Web Training is Australia's leading provider of instructor led software training. We offer training courses in Adobe, Web Design, Graphic Design, Photoshop, InDesign, Dreamweaver and many more.\",\"sameAs\":[\"https:\/\/www.facebook.com\/DynamicWebTraining\/\",\"https:\/\/www.linkedin.com\/company\/dynamic-web-training\",\"https:\/\/twitter.com\/dynamicwebtrain\"]}]}<\/script>","_links":{"self":[{"href":"https:\/\/www.dynamicwebtraining.com.au\/blog\/wp-json\/wp\/v2\/posts\/1396","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dynamicwebtraining.com.au\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dynamicwebtraining.com.au\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dynamicwebtraining.com.au\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dynamicwebtraining.com.au\/blog\/wp-json\/wp\/v2\/comments?post=1396"}],"version-history":[{"count":19,"href":"https:\/\/www.dynamicwebtraining.com.au\/blog\/wp-json\/wp\/v2\/posts\/1396\/revisions"}],"predecessor-version":[{"id":1944,"href":"https:\/\/www.dynamicwebtraining.com.au\/blog\/wp-json\/wp\/v2\/posts\/1396\/revisions\/1944"}],"wp:attachment":[{"href":"https:\/\/www.dynamicwebtraining.com.au\/blog\/wp-json\/wp\/v2\/media?parent=1396"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dynamicwebtraining.com.au\/blog\/wp-json\/wp\/v2\/categories?post=1396"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dynamicwebtraining.com.au\/blog\/wp-json\/wp\/v2\/tags?post=1396"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}