<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: cenan ozen</title>
    <description>The latest articles on DEV Community by cenan ozen (@cenan).</description>
    <link>https://dev.to/cenan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F298120%2F090148da-0bb9-4b4a-bcf9-09c6c6989429.jpeg</url>
      <title>DEV Community: cenan ozen</title>
      <link>https://dev.to/cenan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cenan"/>
    <language>en</language>
    <item>
      <title>Exploring String Field Types in Databases: CHAR, VARCHAR, and TEXT</title>
      <dc:creator>cenan ozen</dc:creator>
      <pubDate>Fri, 06 Oct 2023 10:31:37 +0000</pubDate>
      <link>https://dev.to/dbmodeller/exploring-string-field-types-in-databases-char-varchar-and-text-50gh</link>
      <guid>https://dev.to/dbmodeller/exploring-string-field-types-in-databases-char-varchar-and-text-50gh</guid>
      <description>&lt;p&gt;In this post, we will explore and compare the different string field types commonly used in databases: &lt;code&gt;CHAR&lt;/code&gt;, &lt;code&gt;VARCHAR&lt;/code&gt;, and &lt;code&gt;TEXT&lt;/code&gt;. We will discuss their characteristics, use cases, and the considerations that DBAs and developers should keep in mind when choosing the right string field type.&lt;/p&gt;

&lt;p&gt;Which string type you choose will depend on the specific needs of your application. If you need to store a fixed length string, such as a ZIP code, then you should use a &lt;code&gt;CHAR&lt;/code&gt; column. If you need to store a variable-length string, such as a customer name, then you should use a &lt;code&gt;VARCHAR&lt;/code&gt; column. If you need to store a very large string, or binary data, then you should use a &lt;code&gt;TEXT&lt;/code&gt; or BLOB column.&lt;/p&gt;

&lt;h2&gt;
  
  
  Limitations
&lt;/h2&gt;

&lt;p&gt;There usually is a limit, for the length of the field depending on the type.&lt;/p&gt;

&lt;p&gt;Here are the maximum VARCHAR field sizes for some common databases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;MySQL:
the maximum size of a VARCHAR field is 65,535 bytes.&lt;/li&gt;
&lt;li&gt;PostgreSQL:
the maximum size of a VARCHAR field is 1,073,741,823 characters. (1 GB)&lt;/li&gt;
&lt;li&gt;Oracle Database:
the maximum size of a VARCHAR field is 4,000 bytes (which can be fewer than 4,000 characters, depending on character encoding).&lt;/li&gt;
&lt;li&gt;Microsoft SQL Server:
the maximum size of a VARCHAR field is 8,000 bytes.&lt;/li&gt;
&lt;li&gt;SQLite:
the maximum size of a VARCHAR field is 2,147,483,647 bytes. (2 GB)&lt;/li&gt;
&lt;li&gt;IBM Db2:
In IBM Db2, the maximum size of a VARCHAR field depends on the version and configuration, but it is typically at least 32,767 bytes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;and for the &lt;code&gt;CHAR&lt;/code&gt; type:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In MySQL, the maximum size of a CHAR field is 255 characters. However, this limit can be increased to 65,535 characters by modifying the row format to DYNAMIC or COMPRESSED.&lt;/li&gt;
&lt;li&gt;PostgreSQL: the maximum size of a CHAR field is 1,073,741,823 characters.&lt;/li&gt;
&lt;li&gt;Oracle Database, the maximum size of a CHAR field is 2,000 bytes (which can be fewer than 2,000 characters, depending on character encoding).&lt;/li&gt;
&lt;li&gt;Microsoft SQL Server: the maximum size of a CHAR field is 8,000 bytes.&lt;/li&gt;
&lt;li&gt;In SQLite, the maximum size of a CHAR field is 2,147,483,647 bytes.&lt;/li&gt;
&lt;li&gt;In IBM Db2, the maximum size of a CHAR field depends on the version and configuration, but it is typically at least 32,767 bytes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;and finally for the &lt;code&gt;TEXT&lt;/code&gt; field type:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Database&lt;/th&gt;
&lt;th&gt;Maximum size&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;MySQL&lt;/td&gt;
&lt;td&gt;4 GB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PostgreSQL&lt;/td&gt;
&lt;td&gt;1 GB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Oracle Database&lt;/td&gt;
&lt;td&gt;4 GB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Microsoft SQL Server&lt;/td&gt;
&lt;td&gt;2 GB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;IBM DB2&lt;/td&gt;
&lt;td&gt;2 GB&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Performance
&lt;/h2&gt;

&lt;p&gt;Which string type you choose will also affect the performance of your database application. &lt;code&gt;CHAR&lt;/code&gt; columns are generally the fastest, followed by &lt;code&gt;VARCHAR&lt;/code&gt; columns. &lt;code&gt;TEXT&lt;/code&gt; and BLOB columns are the slowest.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Thank you for reading, and see you on another post 👋👋&lt;/p&gt;

</description>
      <category>database</category>
      <category>db</category>
      <category>dba</category>
      <category>sql</category>
    </item>
    <item>
      <title>Types of SQL Joins</title>
      <dc:creator>cenan ozen</dc:creator>
      <pubDate>Wed, 14 Dec 2022 20:29:55 +0000</pubDate>
      <link>https://dev.to/dbmodeller/types-of-sql-joins-37e6</link>
      <guid>https://dev.to/dbmodeller/types-of-sql-joins-37e6</guid>
      <description>&lt;p&gt;In SQL, a join is a way to combine data from multiple tables based on a related column between them. This allows you to query data from multiple tables in a single statement. In this article, we will explore the different types of joins in SQL.&lt;/p&gt;

&lt;p&gt;There are several different types of joins in SQL, including &lt;strong&gt;inner joins&lt;/strong&gt;, &lt;strong&gt;outer joins&lt;/strong&gt;, &lt;strong&gt;cross joins&lt;/strong&gt;. and &lt;strong&gt;self joins&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;We will use the following &lt;code&gt;users&lt;/code&gt; and &lt;code&gt;posts&lt;/code&gt; tables for our examples:&lt;/p&gt;

&lt;p&gt;users:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;id&lt;/th&gt;
&lt;th&gt;name&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Harold&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Lionel&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;posts:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;id&lt;/th&gt;
&lt;th&gt;user_id&lt;/th&gt;
&lt;th&gt;caption&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;foo&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;bar&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;baz&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;NULL&lt;/td&gt;
&lt;td&gt;qux&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Inner Join
&lt;/h2&gt;

&lt;p&gt;Inner joins are the most common type of join and are used to combine rows from two or more tables based on a related column between them. It is the default join, which is used when you don't specify a join type in your SQL statement.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;
&lt;span class="k"&gt;INNER&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt;
&lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This statement would return all rows from &lt;code&gt;users&lt;/code&gt; and &lt;code&gt;posts&lt;/code&gt; where the &lt;code&gt;id&lt;/code&gt; column is the same in both tables. The resulting table would include only the columns from &lt;code&gt;users&lt;/code&gt; and &lt;code&gt;posts&lt;/code&gt;, and would include a row for each pair of matching rows from the two tables.&lt;/p&gt;

&lt;p&gt;Result:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;id&lt;/th&gt;
&lt;th&gt;name&lt;/th&gt;
&lt;th&gt;id&lt;/th&gt;
&lt;th&gt;user_id&lt;/th&gt;
&lt;th&gt;caption&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;foo&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;bar&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Harold&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;baz&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Let's visualize the result as sets so we can understand it better. The blue are is our result set:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdbmodeller.net%2Fblog%2Fassets%2Fjoin_inner.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdbmodeller.net%2Fblog%2Fassets%2Fjoin_inner.png" alt="Inner Join"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Outer Joins
&lt;/h2&gt;

&lt;p&gt;An outer join, on the other hand, is a type of join that combines rows from two or more tables and includes unmatched rows from one or more tables. There are three types of outer joins: left, right, and full.&lt;/p&gt;

&lt;h2&gt;
  
  
  Left Outer Join
&lt;/h2&gt;

&lt;p&gt;A left outer join includes all the rows from the left table, and the matched rows from the right table.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;
&lt;span class="k"&gt;LEFT&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt;
&lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;id&lt;/th&gt;
&lt;th&gt;name&lt;/th&gt;
&lt;th&gt;id&lt;/th&gt;
&lt;th&gt;user_id&lt;/th&gt;
&lt;th&gt;caption&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;foo&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;bar&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Harold&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;baz&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Lionel&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;And as a set:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdbmodeller.net%2Fblog%2Fassets%2Fjoin_left.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdbmodeller.net%2Fblog%2Fassets%2Fjoin_left.png" alt="Left Outer Join"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before we go on and talk about right joins, looking at the above picture, what if we want to get the difference of the left set from the right one without the intersection?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdbmodeller.net%2Fblog%2Fassets%2Fjoin_left_difference.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdbmodeller.net%2Fblog%2Fassets%2Fjoin_left_difference.png" alt="Left Outer Join Without the intersection"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In that case we should add a where condition that eliminates the intersection from the result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;
&lt;span class="k"&gt;LEFT&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt;
&lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt; &lt;span class="k"&gt;IS&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;id&lt;/th&gt;
&lt;th&gt;name&lt;/th&gt;
&lt;th&gt;id&lt;/th&gt;
&lt;th&gt;user_id&lt;/th&gt;
&lt;th&gt;caption&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Lionel&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;As you see, we have the previous result minus the inner join.&lt;/p&gt;

&lt;h2&gt;
  
  
  Right Outer join
&lt;/h2&gt;

&lt;p&gt;A right outer join includes &lt;strong&gt;all the rows&lt;/strong&gt; from the right table, and the &lt;strong&gt;matched rows&lt;/strong&gt; from the left table. It is basically the symmetrical to the left outer join.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;
&lt;span class="k"&gt;RIGHT&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt;
&lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;id&lt;/th&gt;
&lt;th&gt;user_id&lt;/th&gt;
&lt;th&gt;caption&lt;/th&gt;
&lt;th&gt;id&lt;/th&gt;
&lt;th&gt;name&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;foo&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;bar&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;baz&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Harold&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;NULL&lt;/td&gt;
&lt;td&gt;qux&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdbmodeller.net%2Fblog%2Fassets%2Fjoin_right.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdbmodeller.net%2Fblog%2Fassets%2Fjoin_right.png" alt="Right Outer Join"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Full Outer Join
&lt;/h2&gt;

&lt;p&gt;And a full outer join includes &lt;strong&gt;all the rows&lt;/strong&gt; from &lt;strong&gt;both&lt;/strong&gt; tables, whether they are matched or not.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;
&lt;span class="k"&gt;FULL&lt;/span&gt; &lt;span class="k"&gt;OUTER&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt;
&lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;id&lt;/th&gt;
&lt;th&gt;name&lt;/th&gt;
&lt;th&gt;id&lt;/th&gt;
&lt;th&gt;user_id&lt;/th&gt;
&lt;th&gt;caption&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;foo&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;bar&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Harold&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;baz&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Lionel&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;NULL&lt;/td&gt;
&lt;td&gt;qux&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdbmodeller.net%2Fblog%2Fassets%2Fjoin_full_outer.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdbmodeller.net%2Fblog%2Fassets%2Fjoin_full_outer.png" alt="Full Outer Join"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Cross Join
&lt;/h2&gt;

&lt;p&gt;A cross join, also known as a &lt;em&gt;cartesian join&lt;/em&gt;, is a type of join in SQL that combines every row from one table with every row from another table, resulting in a cartesian product. Here is an example of a cross join:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;
&lt;span class="k"&gt;CROSS&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;id&lt;/th&gt;
&lt;th&gt;name&lt;/th&gt;
&lt;th&gt;id&lt;/th&gt;
&lt;th&gt;user_id&lt;/th&gt;
&lt;th&gt;caption&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;foo&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;bar&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;baz&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;qux&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Harold&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;foo&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Harold&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;bar&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Harold&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;baz&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Harold&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;qux&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Lionel&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;foo&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Lionel&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;bar&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Lionel&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;baz&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Lionel&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;qux&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This statement combines every row from &lt;code&gt;users&lt;/code&gt; with every row from &lt;code&gt;posts&lt;/code&gt;, resulting in a table with the columns from both &lt;code&gt;users&lt;/code&gt; and &lt;code&gt;posts&lt;/code&gt;. The number of rows in the resulting table would be the product of the number of rows in &lt;code&gt;users&lt;/code&gt; and the number of rows in &lt;code&gt;posts&lt;/code&gt;. It is important to note that a cross join does not have a join condition, and as such, it will return a cartesian product even if the tables have no matching rows. Because of this, cross joins are not often used in practice, and other types of joins, such as inner or outer joins, are generally preferred.&lt;/p&gt;

&lt;h2&gt;
  
  
  Self-join
&lt;/h2&gt;

&lt;p&gt;This type of join is used to join a table to itself, using an alias for the second instance of the table. It is often used to compare values within a single table.&lt;/p&gt;

&lt;p&gt;Using our example tables for a self join wouldn't make a lot of sense, but let's write the code to see the syntax and the results anyway.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="n"&gt;u1&lt;/span&gt;
&lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="n"&gt;u2&lt;/span&gt;
&lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;u1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;u2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;id&lt;/th&gt;
&lt;th&gt;name&lt;/th&gt;
&lt;th&gt;id&lt;/th&gt;
&lt;th&gt;name&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;John&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Harold&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Harold&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Lionel&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Lionel&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;And that's all about the different types of &lt;em&gt;joins&lt;/em&gt; in SQL. I hope this will be useful for you to understand their differences.&lt;/p&gt;

&lt;p&gt;Thank you for reading, and see you on another post 👋👋&lt;/p&gt;

</description>
      <category>sql</category>
      <category>tutorial</category>
      <category>database</category>
    </item>
    <item>
      <title>Bookstore Database Schema</title>
      <dc:creator>cenan ozen</dc:creator>
      <pubDate>Wed, 23 Nov 2022 16:42:36 +0000</pubDate>
      <link>https://dev.to/dbmodeller/bookstore-database-schema-13n8</link>
      <guid>https://dev.to/dbmodeller/bookstore-database-schema-13n8</guid>
      <description>&lt;p&gt;In this post we will design a schema to be used in a bookstore software or an online store selling books.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb3ngtupw98ashb1c3cvm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb3ngtupw98ashb1c3cvm.png" alt="Bookstore Schema" width="800" height="415"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;books&lt;/code&gt; is the first table we are going to create and it will hold information about the books themselves.&lt;/p&gt;

&lt;p&gt;Primary fields of the &lt;code&gt;books&lt;/code&gt; table that holds direct information about a book are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;title&lt;/code&gt; — Title of the book&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ISBN_13&lt;/code&gt; — 13 digit ISBN number of the book&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;publication_date&lt;/code&gt; — Date of publication&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;page_count&lt;/code&gt; — Number of pages in the book&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;edition_number&lt;/code&gt; — Edition number&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If we want hold the older 10 digit ISBN code for a book we could add an  &lt;code&gt;ISBN_10&lt;/code&gt; varchar(10) field.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;page_count&lt;/code&gt; field holds the number of pages in the book and we have a field to hold edition number. However, if we want to hold page counts in each edition separately, we might want to create a related &lt;code&gt;editions&lt;/code&gt; table and keep edition specific information in that table.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flxkq9sjqyqsz3qjcrh8d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flxkq9sjqyqsz3qjcrh8d.png" alt="Books Table" width="746" height="770"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we have &lt;code&gt;genres&lt;/code&gt;, &lt;code&gt;publishers&lt;/code&gt; and &lt;code&gt;languages&lt;/code&gt; tables. These tables are connected to the &lt;code&gt;books&lt;/code&gt; table using a many-to-one relation. If we want a book to have more than one &lt;em&gt;genre&lt;/em&gt;, &lt;em&gt;publisher&lt;/em&gt; or &lt;em&gt;language&lt;/em&gt;, then we would need to create join tables and have &lt;code&gt;many-to-many&lt;/code&gt; relations.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9tmdtfz3gmd6kx0rpw2q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9tmdtfz3gmd6kx0rpw2q.png" alt="Genres, publishers, languages" width="800" height="482"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are going to create an &lt;code&gt;authors&lt;/code&gt; table to represent book authors. Since a book can have multiple authors and an author can have multiple books, the relation between &lt;code&gt;books&lt;/code&gt; and &lt;code&gt;authors&lt;/code&gt; will be many-to-many. We have an &lt;code&gt;author_books&lt;/code&gt; &lt;em&gt;join-table&lt;/em&gt; for the needed relation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F90ir2l5470sa7ksthl5x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F90ir2l5470sa7ksthl5x.png" alt="Authors" width="800" height="486"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have an optional &lt;em&gt;Orders&lt;/em&gt; and &lt;em&gt;Customers&lt;/em&gt; part that could be useful for an online book shop.&lt;/p&gt;

&lt;p&gt;General order information is kept in the &lt;code&gt;orders&lt;/code&gt; table, and individual books in an order are kept in the &lt;code&gt;order_items&lt;/code&gt; table.&lt;/p&gt;

&lt;p&gt;Order items have the following fields:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;line_price&lt;/code&gt; a field for the books price in this order. We could have a &lt;code&gt;current_price&lt;/code&gt; field in the books for any listing or report, but since that price can change in time, we must have a constant price associated with the order.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;amount&lt;/code&gt; field holds the count of a specific book in an order.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq5avtd33rcdywd104saz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq5avtd33rcdywd104saz.png" alt="Orders" width="800" height="405"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have the following generic tables related to customers, which are not specifically related to bookstores.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0ir6e5ngn4r3hnnm6t0c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0ir6e5ngn4r3hnnm6t0c.png" alt="Customers" width="800" height="384"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Those are the basic tables that we would need to design a bookstore schema. If we were developing an online store we could add &lt;code&gt;reviews&lt;/code&gt;, &lt;code&gt;ratings&lt;/code&gt; and similar tables. We have used a similar structure in our &lt;a href="https://dbmodeller.net/blog/schema/2022/10/09/movie-catalog-database-schema.html" rel="noopener noreferrer"&gt;movie catalogs&lt;/a&gt; schema tutorial.&lt;/p&gt;

&lt;p&gt;We came to the end of our post. You can open this sample movie catalog schema in &lt;a href="https://dbmodeller.net/" rel="noopener noreferrer"&gt;dbmodeller&lt;/a&gt; and use it in your own projects. You can click &lt;strong&gt;View Samples&lt;/strong&gt; button on the welcome page in &lt;a href="https://dbmodeller.net/" rel="noopener noreferrer"&gt;dbmodeller.net&lt;/a&gt; to checkout other samples.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dbmodeller.net/app/?open_sample=13" rel="noopener noreferrer"&gt;Open Schema in DbModeller&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you for reading 👋👋&lt;/p&gt;

</description>
      <category>gratitude</category>
    </item>
    <item>
      <title>Movie Catalog Database Schema</title>
      <dc:creator>cenan ozen</dc:creator>
      <pubDate>Tue, 18 Oct 2022 18:41:59 +0000</pubDate>
      <link>https://dev.to/dbmodeller/movie-catalog-database-schema-5f1c</link>
      <guid>https://dev.to/dbmodeller/movie-catalog-database-schema-5f1c</guid>
      <description>&lt;p&gt;Today we are going to create a database schema for a movie catalog. It could be used for a web-site like IMDB or a desktop software to catalog movies.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--N5ADnefr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dbmodeller.net/blog/assets/movies-full.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--N5ADnefr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dbmodeller.net/blog/assets/movies-full.png" alt="Movies Schema" width="880" height="384"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our main table to store information about movies is the &lt;code&gt;Movie&lt;/code&gt; table.&lt;br&gt;
This table holds the main aspects of the movie like the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Title of the movie&lt;/li&gt;
&lt;li&gt;Release date&lt;/li&gt;
&lt;li&gt;Run time length of the movie as minutes&lt;/li&gt;
&lt;li&gt;IMDB id of the movie&lt;/li&gt;
&lt;li&gt;MPA Rating of the movie (G, PG, PG-13, R, NC-17)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This table has a reference to &lt;code&gt;languages&lt;/code&gt; table which holds the language of the movie.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zkJ2DFm4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dbmodeller.net/blog/assets/movies-movies-table.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zkJ2DFm4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dbmodeller.net/blog/assets/movies-movies-table.png" alt="Movie Table" width="880" height="519"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next we have the &lt;code&gt;plots&lt;/code&gt;, &lt;code&gt;languages&lt;/code&gt; and &lt;code&gt;genres&lt;/code&gt; tables. These are all colored with the same color because they hold the detail information about a movie.&lt;br&gt;
The &lt;code&gt;plots&lt;/code&gt; table has a many-to-one connection to the &lt;code&gt;movies&lt;/code&gt; table and one-to-one connection to the &lt;code&gt;languages&lt;/code&gt; table. This is because a movie can have multiple plots in different languages. The &lt;code&gt;languages&lt;/code&gt; table is referenced by the &lt;code&gt;movies&lt;/code&gt; table as we have mentioned above. This is for the language of the movie it self.&lt;br&gt;
We have a many-to-many connection between &lt;code&gt;movies&lt;/code&gt; and &lt;code&gt;genres&lt;/code&gt; tables. This is because a movie could have multiple &lt;code&gt;genres&lt;/code&gt;. There is a &lt;code&gt;movie_genres&lt;/code&gt; table to be able to establish the many-to-many connection.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WS_UcAp2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dbmodeller.net/blog/assets/movies-plot-language-genre.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WS_UcAp2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dbmodeller.net/blog/assets/movies-plot-language-genre.png" alt="Movie Details" width="880" height="662"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are many ways to represent people associated with a movie. We could have seperate tables for directors, producers, actors and actresses and these tables could hold that persons details. However we chose to create a single &lt;code&gt;people&lt;/code&gt; table to represent any person and have various &lt;em&gt;join-tables&lt;/em&gt; to represent the association of the specific person to the movie.&lt;/p&gt;

&lt;p&gt;Any person who is not an actor/actress is represented through a record in the &lt;code&gt;people&lt;/code&gt; table and a connection through directors or producers to the &lt;code&gt;movies&lt;/code&gt; table. Depending on our needs, we could add &lt;code&gt;writers&lt;/code&gt;, &lt;code&gt;executive_producers&lt;/code&gt;, &lt;code&gt;production_managers&lt;/code&gt; and many other similar tables with the same structure as &lt;code&gt;producers&lt;/code&gt; and &lt;code&gt;directors&lt;/code&gt; tables. A foreign key for &lt;code&gt;people&lt;/code&gt; and a foreign key for &lt;code&gt;movies&lt;/code&gt; is all that is needed.&lt;/p&gt;

&lt;p&gt;To represent the actors in the database, we will do something different than &lt;code&gt;directors&lt;/code&gt; and &lt;code&gt;producers&lt;/code&gt;. An actor plays a character in a movie. Sometimes a character is played by different actors. For example in &lt;strong&gt;X-Men: First Class (2011)&lt;/strong&gt;, &lt;em&gt;James McAvoy&lt;/em&gt; plays the 30 year old Charles Xavier role and &lt;em&gt;Laurence Belcher&lt;/em&gt; plays the young Xavier role. It is also possible that the same character is portreyed in different movies. Like in the other movies in the series, where Xavier is portraied by &lt;strong&gt;Patrick Stewart&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;To be able to model this scenario where a character is not specifically tied to a movie, we have &lt;code&gt;characters&lt;/code&gt; table which is associated with the &lt;code&gt;movies&lt;/code&gt; table through a &lt;em&gt;join-table&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;em&gt;The correct plural form of person is people, although you can name the &lt;code&gt;people&lt;/code&gt; table &lt;code&gt;persons&lt;/code&gt; if you want to keep the naming consistent.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--d3BNpTG7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dbmodeller.net/blog/assets/movies-people.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--d3BNpTG7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dbmodeller.net/blog/assets/movies-people.png" alt="People" width="880" height="729"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally we have the &lt;code&gt;awards&lt;/code&gt; table. This table would hold the list of awards (94th Academy Awards,  79th Golden Globe Awards, Palme d'Or etc). It has name and year fields of the award, however we could add, &lt;code&gt;ceremony_date&lt;/code&gt;, &lt;code&gt;ceremony_location&lt;/code&gt;, &lt;code&gt;presenter&lt;/code&gt; and many other fields if we need them.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;awards&lt;/code&gt; table is associated with the &lt;code&gt;movies&lt;/code&gt; table through the &lt;code&gt;movie_awards&lt;/code&gt; table. The &lt;code&gt;category&lt;/code&gt; field would hold the name of the award (&lt;em&gt;Best Picture&lt;/em&gt;, &lt;em&gt;Best Actor&lt;/em&gt;, &lt;em&gt;Best Supporting Actress&lt;/em&gt; etc). &lt;code&gt;won_awards&lt;/code&gt; field is a boolean field that represents if the award is won or if it is just a nomination.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JvTD0UkD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dbmodeller.net/blog/assets/movies-awards.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JvTD0UkD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dbmodeller.net/blog/assets/movies-awards.png" alt="Awards" width="880" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We came to the end of our tutorial. You can open this sample movie catalog schema in dbmodeller and use it in your own projects.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dbmodeller.net/app/?open_sample=14"&gt;Open In DbModeller&lt;/a&gt;&lt;/p&gt;

</description>
      <category>database</category>
      <category>schema</category>
      <category>dbschema</category>
    </item>
  </channel>
</rss>
