{"id":3898,"date":"2025-06-06T18:45:43","date_gmt":"2025-06-06T18:45:43","guid":{"rendered":"https:\/\/w3buddy.com\/?post_type=cposts&#038;p=3898"},"modified":"2025-06-07T09:53:55","modified_gmt":"2025-06-07T09:53:55","slug":"sql-statements","status":"publish","type":"cposts","link":"https:\/\/w3buddy.com\/blog\/notes\/sql\/sql-statements\/","title":{"rendered":"SQL Statements"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">SQL statements are the individual commands you use to interact with the database. Each statement tells the database what action to perform \u2014 from retrieving data to modifying the structure.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u270d\ufe0f What Are SQL Statements?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A <strong>SQL statement<\/strong> is a complete instruction made up of one or more clauses. These statements can be grouped into several categories based on their purpose:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Data Query Language (DQL)<\/strong> \u2013 Retrieve data (<code>SELECT<\/code>)<\/li>\n\n\n\n<li><strong>Data Manipulation Language (DML)<\/strong> \u2013 Modify data (<code>INSERT<\/code>, <code>UPDATE<\/code>, <code>DELETE<\/code>)<\/li>\n\n\n\n<li><strong>Data Definition Language (DDL)<\/strong> \u2013 Define or alter database objects (<code>CREATE<\/code>, <code>ALTER<\/code>, <code>DROP<\/code>)<\/li>\n\n\n\n<li><strong>Data Control Language (DCL)<\/strong> \u2013 Manage permissions (<code>GRANT<\/code>, <code>REVOKE<\/code>)<\/li>\n\n\n\n<li><strong>Transaction Control Language (TCL)<\/strong> \u2013 Manage transactions (<code>COMMIT<\/code>, <code>ROLLBACK<\/code>, <code>SAVEPOINT<\/code>)<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u2699\ufe0f Common SQL Statements Overview<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Category<\/th><th>Statement<\/th><th>Purpose<\/th><th>Example<\/th><\/tr><\/thead><tbody><tr><td>DQL<\/td><td><code>SELECT<\/code><\/td><td>Retrieve data from tables<\/td><td><code>SELECT * FROM employees;<\/code><\/td><\/tr><tr><td>DML<\/td><td><code>INSERT<\/code><\/td><td>Add new records<\/td><td><code>INSERT INTO employees (name) VALUES ('Alice');<\/code><\/td><\/tr><tr><td><\/td><td><code>UPDATE<\/code><\/td><td>Modify existing records<\/td><td><code>UPDATE employees SET age = 30 WHERE id = 1;<\/code><\/td><\/tr><tr><td><\/td><td><code>DELETE<\/code><\/td><td>Remove records<\/td><td><code>DELETE FROM employees WHERE age &lt; 20;<\/code><\/td><\/tr><tr><td>DDL<\/td><td><code>CREATE TABLE<\/code><\/td><td>Create a new table<\/td><td><code>CREATE TABLE employees (id INT, name VARCHAR(50));<\/code><\/td><\/tr><tr><td><\/td><td><code>ALTER TABLE<\/code><\/td><td>Change table structure<\/td><td><code>ALTER TABLE employees ADD COLUMN salary INT;<\/code><\/td><\/tr><tr><td><\/td><td><code>DROP TABLE<\/code><\/td><td>Delete a table<\/td><td><code>DROP TABLE employees;<\/code><\/td><\/tr><tr><td>DCL<\/td><td><code>GRANT<\/code><\/td><td>Give permissions to users<\/td><td><code>GRANT SELECT ON employees TO user1;<\/code><\/td><\/tr><tr><td><\/td><td><code>REVOKE<\/code><\/td><td>Remove permissions<\/td><td><code>REVOKE SELECT ON employees FROM user1;<\/code><\/td><\/tr><tr><td>TCL<\/td><td><code>COMMIT<\/code><\/td><td>Save all changes in a transaction<\/td><td><code>COMMIT;<\/code><\/td><\/tr><tr><td><\/td><td><code>ROLLBACK<\/code><\/td><td>Undo changes since last COMMIT<\/td><td><code>ROLLBACK;<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83e\udde9 Statement Syntax Basics<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Every SQL statement has:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>A command keyword<\/strong> (e.g., <code>SELECT<\/code>, <code>INSERT<\/code>)<\/li>\n\n\n\n<li><strong>Optional clauses<\/strong> (e.g., <code>WHERE<\/code>, <code>ORDER BY<\/code>)<\/li>\n\n\n\n<li><strong>Terminates with a semicolon<\/strong> (<code>;<\/code>)<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>SELECT name, age\nFROM employees\nWHERE age &gt; 25\nORDER BY age DESC;<\/code><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udca1 Tips to Remember<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Always end statements with a <strong>semicolon<\/strong>.<\/li>\n\n\n\n<li>Use <strong>uppercase for commands<\/strong> to improve readability.<\/li>\n\n\n\n<li>Write one statement per query execution (unless your database supports batch execution).<\/li>\n\n\n\n<li>Use comments (we\u2019ll cover next) to explain complex queries.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83e\udde0 Quick Recap<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Key Point<\/th><th>Details<\/th><\/tr><\/thead><tbody><tr><td>SQL Statement<\/td><td>Command instructing database action<\/td><\/tr><tr><td>Categories<\/td><td>DQL, DML, DDL, DCL, TCL<\/td><\/tr><tr><td>End with semicolon<\/td><td>Marks completion of statement<\/td><\/tr><tr><td>Write clear and readable<\/td><td>Use uppercase commands and formatting<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>SQL statements are the individual commands you use to interact with the database. Each statement tells the database what action to perform \u2014 from retrieving data to modifying the structure. \u270d\ufe0f What Are SQL Statements? A SQL statement is a complete instruction made up of one or more clauses. These statements can be grouped into [&hellip;]<\/p>\n","protected":false},"template":"","meta":{"googlesitekit_rrm_CAowu461DA:productID":""},"categories":[952,979],"class_list":["post-3898","cposts","type-cposts","status-publish","hentry","category-notes","category-sql"],"_links":{"self":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/cposts\/3898","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/cposts"}],"about":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/types\/cposts"}],"wp:attachment":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/media?parent=3898"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/categories?post=3898"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}