CRUD Operations in SQL
Tags: crud, sql, mysql, database
Published: 2023-10-11 01:37:02

<!-- wp:heading -->
<h2 class="wp-block-heading" id="performing-crud-operations-in-sql-create-read-update-and-delete">Performing CRUD Operations in SQL: Create, Read, Update, and Delete</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p><strong>CRUD</strong> is a commonly used acronym in software and application development. The acronym describes the four basic operations that can be performed on a database: <strong>C</strong>reate, <strong>R</strong>ead, <strong>U</strong>pdate, and <strong>D</strong>elete. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>As developers or database administrators, we are often tasked with creating user roles that carry different CRUD permissions. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":1628,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="https://five.co/wp-content/uploads/2023/08/MySQL-CRUD-002-1024x384.png" alt="CRUD operations in SQL: Create, Read, Update, Delete" class="wp-image-1628"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Let's explore how to perform CRUD operations in MySQL. </strong>We will first speak about how to perform CRUD operations on the <em>table </em>level, before also looking at operations on the <em>database </em>level. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>For the purposes of this blog post, we are assuming that you are using MySQL Workbench as your MySQL GUI. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>If you're not using MySQL Workbench, don't worry: the same principles apply to other database administration tools.</p>
<!-- /wp:paragraph -->

<!-- wp:rank-math/toc-block {"headings":[{"key":"57efcc4e-e688-4a08-88c5-ecbf0886a7b7","content":"Performing CRUD Operations in SQL: Create, Read, Update, and Delete","level":2,"link":"#performing-crud-operations-in-sql-create-read-update-and-delete","disable":false,"isUpdated":false,"isGeneratedLink":true},{"key":"856a6c24-81bd-4b9c-99c1-a129dad9dcd8","content":"What Are CRUD Operations in SQL?","level":2,"link":"#what-are-crud-operations-in-sql","disable":false,"isUpdated":false,"isGeneratedLink":true},{"key":"155f9819-37c1-4e27-99a5-c0def5fe4b67","content":"Permissions in a CRUD App","level":3,"link":"#permissions-in-a-crud-app","disable":false,"isUpdated":false,"isGeneratedLink":true},{"key":"58763b83-cfdb-4f57-bb4d-0388226821fc","content":"How to Perform CRUD Operations in MySQL Workbench","level":3,"link":"#how-to-perform-crud-operations-in-my-sql-workbench","disable":false,"isUpdated":false,"isGeneratedLink":true},{"key":"3437462f-8540-4eb4-8827-59e612cb67db","content":"1. Creating Roles","level":4,"link":"#1-creating-roles","disable":false,"isUpdated":false,"isGeneratedLink":true},{"key":"a0a8c2a4-5537-4696-9a7a-32211f9a409e","content":"2. Assigning CRUD Permissions to Roles and Database Tables","level":4,"link":"#2-assigning-crud-permissions-to-roles-and-database-tables","disable":false,"isUpdated":false,"isGeneratedLink":true},{"key":"84f388c4-4755-4e66-a7bf-4f389cd1da51","content":"3. CRUD Operations for Databases and Tables","level":4,"link":"#3-crud-operations-for-databases-and-tables","disable":false,"isUpdated":false,"isGeneratedLink":true},{"key":"65e8eb4e-35e7-428c-81ff-83af777f8c7a","content":"Conclusion","level":2,"link":"#conclusion","disable":false,"isUpdated":false,"isGeneratedLink":true}],"listStyle":"ul"} -->
<div class="wp-block-rank-math-toc-block" id="rank-math-toc"><nav><ul><li class=""><a href="#performing-crud-operations-in-sql-create-read-update-and-delete">Performing CRUD Operations in SQL: Create, Read, Update, and Delete</a></li><li class=""><a href="#what-are-crud-operations-in-sql">What Are CRUD Operations in SQL?</a><ul><li class=""><a href="#permissions-in-a-crud-app">Permissions in a CRUD App</a></li><li class=""><a href="#how-to-perform-crud-operations-in-my-sql-workbench">How to Perform CRUD Operations in MySQL Workbench</a><ul><li class=""><a href="#1-creating-roles">1. Creating Roles</a></li><li class=""><a href="#2-assigning-crud-permissions-to-roles-and-database-tables">2. Assigning CRUD Permissions to Roles and Database Tables</a></li><li class=""><a href="#3-crud-operations-for-databases-and-tables">3. CRUD Operations for Databases and Tables</a></li></ul></li></ul></li><li class=""><a href="#conclusion">Conclusion</a></li></ul></nav></div>
<!-- /wp:rank-math/toc-block -->

<!-- wp:separator -->
<hr class="wp-block-separator has-alpha-channel-opacity"/>
<!-- /wp:separator -->

<!-- wp:heading -->
<h2 class="wp-block-heading" id="what-are-crud-operations-in-sql">What Are CRUD Operations in SQL?</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>CRUD refers to Create, Read, Update, and Delete. Assigning and managing CRUD permissions is a very common task in programming. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>CRUD describes the four basic operations that a user can perform in a database. Users can</p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><!-- wp:list-item -->
<li><em>Create</em> or <em>insert </em>new records into a table,</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li><em>Read</em> or <em>select</em> existing records from a table,</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li><em>Update</em> or <em>modify </em>existing records stored inside a table, or</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li><em>Delete</em> or <em>remove </em>existing records from a table.</li>
<!-- /wp:list-item --></ol>
<!-- /wp:list -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="permissions-in-a-crud-app">Permissions in a CRUD App</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>CRUD permissions refer to the permissions granted to anyone having access to a database to perform all or part of the four basic operations on data: Create, Read, Update, and Delete. By assigning CRUD permissions, developers control and govern access to data stored in a database. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In SQL, CRUD permissions are often managed by granting or revoking permissions to specific users or roles. These permissions are typically set at the database level or on individual tables within the database.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>It's essential to carefully manage CRUD permissions in a web app to protect data from unauthorized access, modification, or deletion.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>By granting the appropriate permissions to trusted users or roles and denying them to others, application developers ensure that only authorized users can interact with the data in the database. This approach helps to maintain data integrity, security, and privacy.</p>
<!-- /wp:paragraph -->

<!-- wp:separator -->
<hr class="wp-block-separator has-alpha-channel-opacity"/>
<!-- /wp:separator -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="how-to-perform-crud-operations-in-my-sql-workbench">How to Perform CRUD Operations in MySQL Workbench</h3>
<!-- /wp:heading -->

<!-- wp:heading {"level":4} -->
<h4 class="wp-block-heading" id="1-creating-roles">1. Creating Roles</h4>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Before we assign permissions or manage access, we must first define Roles. Roles are a collection of privileges. They save you from the tedious work of assigning CRUD permissions to individual users. Instead, individual users are assigned to Roles, and by default, they will be given the CRUD permissions that are associated with the role.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Typical roles include, for example:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><!-- wp:list-item -->
<li>database administrators with full CRUD permissions,</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>data analysts with partial access, typically <code>READ</code> only, or</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>database developers with CREATE or ALTER access.</li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>To create Roles, use this command:</p>
<!-- /wp:paragraph -->

<!-- wp:kevinbatdorf/code-block-pro {"code":"CREATE ROLE 'database_administrator', 'data_analyst', 'database_developer';","codeHTML":"\u003cpre class=\u0022shiki one-dark-pro\u0022 style=\u0022background-color: #282c34\u0022 tabindex=\u00220\u0022\u003e\u003ccode\u003e\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003eCREATE\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003eROLE\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #98C379\u0022\u003e\u0026#39;database_administrator\u0026#39;\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e, \u003c/span\u003e\u003cspan style=\u0022color: #98C379\u0022\u003e\u0026#39;data_analyst\u0026#39;\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e, \u003c/span\u003e\u003cspan style=\u0022color: #98C379\u0022\u003e\u0026#39;database_developer\u0026#39;\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e;\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e","language":"javascript","theme":"one-dark-pro","bgColor":"#282c34","textColor":"#abb2bf","fontSize":".875rem","fontFamily":"Code-Pro-JetBrains-Mono","lineHeight":"1.25rem","headerType":"headlights","seeMoreString":"","seeMoreAfterLine":"","seeMoreTransition":false,"lineHighlightColor":"rgba(134, 167, 228, 0.2)","copyButton":true,"buttonTheme":"heroicons"} -->
<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="CREATE ROLE 'database_administrator', 'data_analyst', 'database_developer';" style="color:#abb2bf;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki one-dark-pro" style="background-color: #282c34" tabindex="0"><code><span class="line"><span style="color: #E5C07B">CREATE</span><span style="color: #ABB2BF"> </span><span style="color: #E5C07B">ROLE</span><span style="color: #ABB2BF"> </span><span style="color: #98C379">&#39;database_administrator&#39;</span><span style="color: #ABB2BF">, </span><span style="color: #98C379">&#39;data_analyst&#39;</span><span style="color: #ABB2BF">, </span><span style="color: #98C379">&#39;database_developer&#39;</span><span style="color: #ABB2BF">;</span></span></code></pre></div>
<!-- /wp:kevinbatdorf/code-block-pro -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In case you would like to delete a role instead, use <code>DROP ROLE</code>.</p>
<!-- /wp:paragraph -->

<!-- wp:separator -->
<hr class="wp-block-separator has-alpha-channel-opacity"/>
<!-- /wp:separator -->

<!-- wp:heading {"level":4} -->
<h4 class="wp-block-heading" id="2-assigning-crud-permissions-to-roles-and-database-tables">2. Assigning CRUD Permissions to Roles and Database Tables</h4>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>In MySQL Workbench, CRUD operations can be performed on tables, or sets of tables. To manage CRUD permissions, MySQL offers granular access control features through its standard syntax. We've already looked at <code>CREATE ROLE</code>. So now, let's move on and grant our roles permissions by using <code>GRANT</code>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To assign CRUD permissions for tables, and to the records contained inside of them, developers can use the <code>GRANT</code> statement.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The <code>GRANT</code> statement allows administrators to grant specific privileges to users or to roles on specific database objects. Permissions can be assigned in point-and-click by using Workbench's Role Editor.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":1607,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-full"><img src="https://five.co/wp-content/uploads/2023/08/image-32.png" alt="To perform CRUD operations in MySQL, we must first define roles and grant them privileges." class="wp-image-1607"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To assign CRUD permissions in MySQL Workbench, follow these steps:</p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><!-- wp:list-item -->
<li>Connect to your MySQL database using MySQL Workbench.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Navigate to the "<strong>Server Administration</strong>" tab and select the "<strong>Users and Privileges</strong>" option.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Select the user or role to whom you want to assign CRUD permissions.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Click on the "<strong>Schema Privileges</strong>" tab and select the database schema where the table resides.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Find the table for which you want to assign CRUD permissions, and select the checkboxes for the appropriate privileges: <code>INSERT</code>, <code>SELECT</code>, <code>UPDATE</code>, and <code>DELETE</code>. Note that </li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Click "<strong>Apply</strong>" to save the changes and assign the CRUD permissions to the user or role.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Once equipped with the right set of permissions, different roles can perform CRUD operations in SQL. </li>
<!-- /wp:list-item --></ol>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>Alternatively, you can also assign CRUD permissions using SQL commands. For example, to grant a user permission to perform all CRUD operations on a specific table in a MySQL database, you can use the following command:</p>
<!-- /wp:paragraph -->

<!-- wp:kevinbatdorf/code-block-pro {"code":"GRANT SELECT, INSERT, UPDATE, DELETE ON database.table TO 'database_administrator'@'localhost';","codeHTML":"\u003cpre class=\u0022shiki one-dark-pro\u0022 style=\u0022background-color: #282c34\u0022 tabindex=\u00220\u0022\u003e\u003ccode\u003e\u003cspan class=\u0022line\u0022\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003eGRANT\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003eSELECT\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e, \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003eINSERT\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e, \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003eUPDATE\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e, \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003eDELETE\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003eON\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003edatabase\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e.\u003c/span\u003e\u003cspan style=\u0022color: #E06C75\u0022\u003etable\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #E5C07B\u0022\u003eTO\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e \u003c/span\u003e\u003cspan style=\u0022color: #98C379\u0022\u003e\u0026#39;database_administrator\u0026#39;\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e@\u003c/span\u003e\u003cspan style=\u0022color: #98C379\u0022\u003e\u0026#39;localhost\u0026#39;\u003c/span\u003e\u003cspan style=\u0022color: #ABB2BF\u0022\u003e;\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e","language":"javascript","theme":"one-dark-pro","bgColor":"#282c34","textColor":"#abb2bf","fontSize":".875rem","fontFamily":"Code-Pro-JetBrains-Mono","lineHeight":"1.25rem","headerType":"headlights","seeMoreString":"","seeMoreAfterLine":"","seeMoreTransition":false,"lineHighlightColor":"rgba(134, 167, 228, 0.2)","copyButton":true,"buttonTheme":"heroicons"} -->
<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282c34"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="GRANT SELECT, INSERT, UPDATE, DELETE ON database.table TO 'database_administrator'@'localhost';" style="color:#abb2bf;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki one-dark-pro" style="background-color: #282c34" tabindex="0"><code><span class="line"><span style="color: #E5C07B">GRANT</span><span style="color: #ABB2BF"> </span><span style="color: #E5C07B">SELECT</span><span style="color: #ABB2BF">, </span><span style="color: #E5C07B">INSERT</span><span style="color: #ABB2BF">, </span><span style="color: #E5C07B">UPDATE</span><span style="color: #ABB2BF">, </span><span style="color: #E5C07B">DELETE</span><span style="color: #ABB2BF"> </span><span style="color: #E5C07B">ON</span><span style="color: #ABB2BF"> </span><span style="color: #E5C07B">database</span><span style="color: #ABB2BF">.</span><span style="color: #E06C75">table</span><span style="color: #ABB2BF"> </span><span style="color: #E5C07B">TO</span><span style="color: #ABB2BF"> </span><span style="color: #98C379">&#39;database_administrator&#39;</span><span style="color: #ABB2BF">@</span><span style="color: #98C379">&#39;localhost&#39;</span><span style="color: #ABB2BF">;</span></span></code></pre></div>
<!-- /wp:kevinbatdorf/code-block-pro -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This command grants the user "database_administrator" permission to perform all four CRUD operations on the table named 'table' in the database named 'database'. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The '@' symbol followed by 'localhost' indicates that the permission applies only to connections made from the same computer as the MySQL server. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Note how we have used the <code>SELECT, INSERT, UPDATE, </code>and<code> DELETE</code> operations in SQL. Why doesn't MySQL use CREATE, READ, UPDATE, and DELETE to describe these operations? </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>That's because CREATE is already reserved for another purpose. Let's look at this next.</p>
<!-- /wp:paragraph -->

<!-- wp:separator -->
<hr class="wp-block-separator has-alpha-channel-opacity"/>
<!-- /wp:separator -->

<!-- wp:heading {"level":4} -->
<h4 class="wp-block-heading" id="3-crud-operations-for-databases-and-tables">3. CRUD Operations for Databases and Tables</h4>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Why does the <code>GRANT</code> statement not include <code>CREATE</code> and <code>READ</code>? Well, this is a bit of a trick question, because there is no <code>READ</code> operation in MySQL. There is, however, a <code>CREATE</code> statement. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The correct syntax of the <code>CREATE </code>statement is this: <code>CREATE DATABASE</code>. It is used to create a new SQL database, and <em>not </em>to create database records.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>So, on a database level, the syntax is as follows:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><!-- wp:list-item -->
<li>CREATE: used to create a database like so: <code>CREATE DATABASE</code></li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>READ: This only applies to the table level.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>UPDATE: <code>ALTER TABLE</code>. Altering a table could, for example, mean adding or deleting a field inside a table. This is different from the <code>UPDATE </code>statement above, which only updates an existing record inside a table.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>DELETE: <code>DROP DATABASE</code> or <code>DROP TABLE</code></li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->

<!-- wp:separator -->
<hr class="wp-block-separator has-alpha-channel-opacity"/>
<!-- /wp:separator -->

<!-- wp:heading -->
<h2 class="wp-block-heading" id="conclusion">Conclusion</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Let's say you are a restaurant owner and you'd like to make sure your staff can enter the kitchen, but your guests can only stay in the dining room. How would you solve this problem? Easy! You have two roles: staff and guest. Each role has its own permission to enter different parts of the restaurant.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This is what CRUD permissions do for databases: they are used to govern access. By using CRUD operations in SQL, developers can make sure that data stays safe and is only accessed as intended. CRUD permissions are a useful tool in a developer's access control toolbox!</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To build CRUD web applications on a MySQL database, check out Five. Five is an easy way to manage a MySQL database, as well as its front end all from one platform. To sign up for a free download, <a href="https://five.co/sign-up" data-type="URL" data-id="https://five.co/sign-up">click here</a>!        </p>
<!-- /wp:paragraph -->