{"id":1664,"date":"2020-06-10T04:11:55","date_gmt":"2020-06-10T11:11:55","guid":{"rendered":"https:\/\/renanmf.com\/?p=1664"},"modified":"2021-02-13T22:45:35","modified_gmt":"2021-02-14T01:45:35","slug":"sql-tables-and-basic-structure","status":"publish","type":"post","link":"https:\/\/renanmf.com\/sql-tables-and-basic-structure\/","title":{"rendered":"SQL: Tables and Basic Structure"},"content":{"rendered":"<p>This is a direct continuation of my previous article <a href=\"https:\/\/renanmf.com\/introduction-to-sql\/\">Introduction to SQL<\/a>.<\/p>\n<p>SQL works on a structure with four components: Table, Field, Row, and Column.<\/p>\n<p>You can think of those components exactly like the ones in spreadsheets like Excel.<\/p>\n<p>A database can have one or more tables in it.<\/p>\n<h2>Table<\/h2>\n<p>A table is a very common and simple way to organize data.<\/p>\n<p>You have columns describe the kind of information and rows\/records consisting of the information itself.<\/p>\n<p>The following two tables Employees and Departments are the ones I will use to demonstrate the capabilities of SQL and how to manage data.<\/p>\n<p>The Employees table contains data about the employees of a certain company.<\/p>\n<p><strong>Employees<\/strong><\/p>\n<pre><code>| employee_id | name  |   job_title   | salary | hire_date  | department_id |\n|-------------|-------|---------------|--------|------------|---------------|\n| 1           | Bob   | Engineer      | 80000  | 2015-04-12 | 2             |\n| 2           | Mary  | Designer      | 60000  | 2017-06-21 | 2             |\n| 3           | Sarah | Sales Manager | 98000  | 2013-09-05 | 1             |\n| 4           | Peter | IT Manager    | 95000  | 2010-09-05 | 2             |\n| 5           | Brian | HR Manager    | 92000  | 2012-09-05 | 3             |<\/code><\/pre>\n<p>The Departments table describes de departments the company has.<\/p>\n<p><strong>Departments<\/strong><\/p>\n<pre><code>| department_id | department_name | city      | country | manager_id |\n|---------------|-----------------|-----------|---------|------------|\n| 1             | Sales           | S\u00e3o Paulo | Brazil  | 3          |\n| 2             | IT              | Barcelona | Spain   | 4          |\n| 3             | Human Resources | New York  | USA     | 5          |<\/code><\/pre>\n<h2>Field<\/h2>\n<p>A field specifies the kind of information a particular column has and its type.<\/p>\n<p>The Employees table has the following fields:<\/p>\n<ul>\n<li>employee_id: de unique ID that identifies an employee<\/li>\n<li>name: the name of the employee<\/li>\n<li>job_title: the formal title the employee has inside the company<\/li>\n<li>salary: how much the employee makes yearly<\/li>\n<li>hire_date: when the employee was hired<\/li>\n<li>department_id: the unique ID of the department where the employee works<\/li>\n<\/ul>\n<p>The Departments table has the following fields:<\/p>\n<ul>\n<li>department_id: the unique ID for the Department<\/li>\n<li>department_name: the name of the Department<\/li>\n<li>city: the city where the Department is located<\/li>\n<li>country: the country where the Department is located<\/li>\n<li>manager_id: the ID of the manager responsible for the department, the manager is an employee<\/li>\n<\/ul>\n<h2>Row<\/h2>\n<p>A row is a record of data inside the Table.<\/p>\n<p>The Employee table has 5 rows.<\/p>\n<p>The first row is Bob\\&#8217;s record.<\/p>\n<p>Notice the row with the identifications of the fields does not count as &quot;first&quot; row, the counting begins with the first record.<\/p>\n<pre><code>| employee_id | name  |   job_title   | salary | hire_date  | department_id |\n|-------------|-------|---------------|--------|------------|---------------|\n| 1           | Bob   | Engineer      | 80000  | 2015-04-12 | 2             |<\/code><\/pre>\n<h2>Column<\/h2>\n<p>A column is a field and all of its information.<\/p>\n<p>The column <code>employee_id<\/code> in the Employees table has all the unique IDs of all the employees.<\/p>\n<pre><code>| employee_id |\n|-------------|\n| 1           |\n| 2           |\n| 3           |\n| 4           |\n| 5           |<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This is a direct continuation of my previous article Introduction to SQL. SQL works on a structure with four components: Table, Field, Row, and Column. You can think of those components exactly like the ones in spreadsheets like Excel. A database can have one or more tables in it. Table A table is a very [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":1767,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,28],"tags":[29],"class_list":["post-1664","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-database","category-sql","tag-sql"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":6}},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>SQL: Tables and Basic Structure<\/title>\n<meta name=\"description\" content=\"Learn the basic structures of a Relational Database: Table, Field, Row, and Column\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/renanmf.com\/sql-tables-and-basic-structure\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL: Tables and Basic Structure\" \/>\n<meta property=\"og:description\" content=\"Learn the basic structures of a Relational Database: Table, Field, Row, and Column\" \/>\n<meta property=\"og:url\" content=\"https:\/\/renanmf.com\/sql-tables-and-basic-structure\/\" \/>\n<meta property=\"og:site_name\" content=\"Renan Moura - Software Engineering\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/renanmouraf\" \/>\n<meta property=\"article:published_time\" content=\"2020-06-10T11:11:55+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-02-14T01:45:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/renanmf.com\/wp-content\/uploads\/2020\/06\/image.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Renan Moura\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/renanmouraf\" \/>\n<meta name=\"twitter:site\" content=\"@renanmouraf\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Renan Moura\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/renanmf.com\\\/sql-tables-and-basic-structure\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/renanmf.com\\\/sql-tables-and-basic-structure\\\/\"},\"author\":{\"name\":\"Renan Moura\",\"@id\":\"https:\\\/\\\/renanmf.com\\\/#\\\/schema\\\/person\\\/1a6fd46256318d200c1c8a867448e5a8\"},\"headline\":\"SQL: Tables and Basic Structure\",\"datePublished\":\"2020-06-10T11:11:55+00:00\",\"dateModified\":\"2021-02-14T01:45:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/renanmf.com\\\/sql-tables-and-basic-structure\\\/\"},\"wordCount\":331,\"publisher\":{\"@id\":\"https:\\\/\\\/renanmf.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/renanmf.com\\\/sql-tables-and-basic-structure\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/renanmf.com\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/image.png\",\"keywords\":[\"sql\"],\"articleSection\":[\"Database\",\"SQL\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/renanmf.com\\\/sql-tables-and-basic-structure\\\/\",\"url\":\"https:\\\/\\\/renanmf.com\\\/sql-tables-and-basic-structure\\\/\",\"name\":\"SQL: Tables and Basic Structure\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/renanmf.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/renanmf.com\\\/sql-tables-and-basic-structure\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/renanmf.com\\\/sql-tables-and-basic-structure\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/renanmf.com\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/image.png\",\"datePublished\":\"2020-06-10T11:11:55+00:00\",\"dateModified\":\"2021-02-14T01:45:35+00:00\",\"description\":\"Learn the basic structures of a Relational Database: Table, Field, Row, and Column\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/renanmf.com\\\/sql-tables-and-basic-structure\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/renanmf.com\\\/sql-tables-and-basic-structure\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/renanmf.com\\\/sql-tables-and-basic-structure\\\/#primaryimage\",\"url\":\"https:\\\/\\\/renanmf.com\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/image.png\",\"contentUrl\":\"https:\\\/\\\/renanmf.com\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/image.png\",\"width\":1200,\"height\":630,\"caption\":\"SQL: Tables and Basic Structure\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/renanmf.com\\\/sql-tables-and-basic-structure\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"In\u00edcio\",\"item\":\"https:\\\/\\\/renanmf.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL: Tables and Basic Structure\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/renanmf.com\\\/#website\",\"url\":\"https:\\\/\\\/renanmf.com\\\/\",\"name\":\"Renan Moura - Software Engineering\",\"description\":\"Software development, machine learning\",\"publisher\":{\"@id\":\"https:\\\/\\\/renanmf.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/renanmf.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/renanmf.com\\\/#organization\",\"name\":\"Renan Moura\",\"url\":\"https:\\\/\\\/renanmf.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/renanmf.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/renanmf.com\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/me-e1583179172701.jpeg\",\"contentUrl\":\"https:\\\/\\\/renanmf.com\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/me-e1583179172701.jpeg\",\"width\":120,\"height\":120,\"caption\":\"Renan Moura\"},\"image\":{\"@id\":\"https:\\\/\\\/renanmf.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/renanmouraf\",\"https:\\\/\\\/x.com\\\/renanmouraf\",\"https:\\\/\\\/instagram.com\\\/renanmouraf\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/renanmouraf\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/renanmf.com\\\/#\\\/schema\\\/person\\\/1a6fd46256318d200c1c8a867448e5a8\",\"name\":\"Renan Moura\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/efb78bdd04aa5627f80307aed5a9b31989d901c536d1e014a29a3c3591338af8?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/efb78bdd04aa5627f80307aed5a9b31989d901c536d1e014a29a3c3591338af8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/efb78bdd04aa5627f80307aed5a9b31989d901c536d1e014a29a3c3591338af8?s=96&d=mm&r=g\",\"caption\":\"Renan Moura\"},\"description\":\"I'm a Software Engineer working in the industry for a decade now. I like to solve problems with as little code as possible. I\u2019m interested in solving all sorts of problems with technology in creative and innovative ways. From everyday shell scripts to machine learning models. I write about Software Development, Machine Learning, and Career in tech.\",\"sameAs\":[\"https:\\\/\\\/renanmf.com\\\/\",\"https:\\\/\\\/www.instagram.com\\\/renanmouraf\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/renanmouraf\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/renanmouraf\"],\"url\":\"https:\\\/\\\/renanmf.com\\\/author\\\/renanmoura\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQL: Tables and Basic Structure","description":"Learn the basic structures of a Relational Database: Table, Field, Row, and Column","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:\/\/renanmf.com\/sql-tables-and-basic-structure\/","og_locale":"en_US","og_type":"article","og_title":"SQL: Tables and Basic Structure","og_description":"Learn the basic structures of a Relational Database: Table, Field, Row, and Column","og_url":"https:\/\/renanmf.com\/sql-tables-and-basic-structure\/","og_site_name":"Renan Moura - Software Engineering","article_publisher":"https:\/\/www.facebook.com\/renanmouraf","article_published_time":"2020-06-10T11:11:55+00:00","article_modified_time":"2021-02-14T01:45:35+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/renanmf.com\/wp-content\/uploads\/2020\/06\/image.png","type":"image\/png"}],"author":"Renan Moura","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/renanmouraf","twitter_site":"@renanmouraf","twitter_misc":{"Written by":"Renan Moura","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/renanmf.com\/sql-tables-and-basic-structure\/#article","isPartOf":{"@id":"https:\/\/renanmf.com\/sql-tables-and-basic-structure\/"},"author":{"name":"Renan Moura","@id":"https:\/\/renanmf.com\/#\/schema\/person\/1a6fd46256318d200c1c8a867448e5a8"},"headline":"SQL: Tables and Basic Structure","datePublished":"2020-06-10T11:11:55+00:00","dateModified":"2021-02-14T01:45:35+00:00","mainEntityOfPage":{"@id":"https:\/\/renanmf.com\/sql-tables-and-basic-structure\/"},"wordCount":331,"publisher":{"@id":"https:\/\/renanmf.com\/#organization"},"image":{"@id":"https:\/\/renanmf.com\/sql-tables-and-basic-structure\/#primaryimage"},"thumbnailUrl":"https:\/\/renanmf.com\/wp-content\/uploads\/2020\/06\/image.png","keywords":["sql"],"articleSection":["Database","SQL"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/renanmf.com\/sql-tables-and-basic-structure\/","url":"https:\/\/renanmf.com\/sql-tables-and-basic-structure\/","name":"SQL: Tables and Basic Structure","isPartOf":{"@id":"https:\/\/renanmf.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/renanmf.com\/sql-tables-and-basic-structure\/#primaryimage"},"image":{"@id":"https:\/\/renanmf.com\/sql-tables-and-basic-structure\/#primaryimage"},"thumbnailUrl":"https:\/\/renanmf.com\/wp-content\/uploads\/2020\/06\/image.png","datePublished":"2020-06-10T11:11:55+00:00","dateModified":"2021-02-14T01:45:35+00:00","description":"Learn the basic structures of a Relational Database: Table, Field, Row, and Column","breadcrumb":{"@id":"https:\/\/renanmf.com\/sql-tables-and-basic-structure\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/renanmf.com\/sql-tables-and-basic-structure\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/renanmf.com\/sql-tables-and-basic-structure\/#primaryimage","url":"https:\/\/renanmf.com\/wp-content\/uploads\/2020\/06\/image.png","contentUrl":"https:\/\/renanmf.com\/wp-content\/uploads\/2020\/06\/image.png","width":1200,"height":630,"caption":"SQL: Tables and Basic Structure"},{"@type":"BreadcrumbList","@id":"https:\/\/renanmf.com\/sql-tables-and-basic-structure\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"In\u00edcio","item":"https:\/\/renanmf.com\/"},{"@type":"ListItem","position":2,"name":"SQL: Tables and Basic Structure"}]},{"@type":"WebSite","@id":"https:\/\/renanmf.com\/#website","url":"https:\/\/renanmf.com\/","name":"Renan Moura - Software Engineering","description":"Software development, machine learning","publisher":{"@id":"https:\/\/renanmf.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/renanmf.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/renanmf.com\/#organization","name":"Renan Moura","url":"https:\/\/renanmf.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/renanmf.com\/#\/schema\/logo\/image\/","url":"https:\/\/renanmf.com\/wp-content\/uploads\/2020\/03\/me-e1583179172701.jpeg","contentUrl":"https:\/\/renanmf.com\/wp-content\/uploads\/2020\/03\/me-e1583179172701.jpeg","width":120,"height":120,"caption":"Renan Moura"},"image":{"@id":"https:\/\/renanmf.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/renanmouraf","https:\/\/x.com\/renanmouraf","https:\/\/instagram.com\/renanmouraf","https:\/\/www.linkedin.com\/in\/renanmouraf\/"]},{"@type":"Person","@id":"https:\/\/renanmf.com\/#\/schema\/person\/1a6fd46256318d200c1c8a867448e5a8","name":"Renan Moura","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/efb78bdd04aa5627f80307aed5a9b31989d901c536d1e014a29a3c3591338af8?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/efb78bdd04aa5627f80307aed5a9b31989d901c536d1e014a29a3c3591338af8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/efb78bdd04aa5627f80307aed5a9b31989d901c536d1e014a29a3c3591338af8?s=96&d=mm&r=g","caption":"Renan Moura"},"description":"I'm a Software Engineer working in the industry for a decade now. I like to solve problems with as little code as possible. I\u2019m interested in solving all sorts of problems with technology in creative and innovative ways. From everyday shell scripts to machine learning models. I write about Software Development, Machine Learning, and Career in tech.","sameAs":["https:\/\/renanmf.com\/","https:\/\/www.instagram.com\/renanmouraf\/","https:\/\/www.linkedin.com\/in\/renanmouraf\/","https:\/\/x.com\/https:\/\/twitter.com\/renanmouraf"],"url":"https:\/\/renanmf.com\/author\/renanmoura\/"}]}},"_links":{"self":[{"href":"https:\/\/renanmf.com\/wp-json\/wp\/v2\/posts\/1664","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/renanmf.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/renanmf.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/renanmf.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/renanmf.com\/wp-json\/wp\/v2\/comments?post=1664"}],"version-history":[{"count":32,"href":"https:\/\/renanmf.com\/wp-json\/wp\/v2\/posts\/1664\/revisions"}],"predecessor-version":[{"id":3001,"href":"https:\/\/renanmf.com\/wp-json\/wp\/v2\/posts\/1664\/revisions\/3001"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/renanmf.com\/wp-json\/wp\/v2\/media\/1767"}],"wp:attachment":[{"href":"https:\/\/renanmf.com\/wp-json\/wp\/v2\/media?parent=1664"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/renanmf.com\/wp-json\/wp\/v2\/categories?post=1664"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/renanmf.com\/wp-json\/wp\/v2\/tags?post=1664"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}