🧰 SQL Getting Started
Estimated reading: 5 minutes 34 views

🧾 SQL Syntax Guide for Beginners – SELECT, INSERT, UPDATE

🧲 Introduction – Why SQL Syntax Matters

Every SQL operationβ€”from querying a customer database to creating an entire data warehouseβ€”starts with correct syntax. SQL syntax defines how statements are written so the database engine can interpret and execute your instructions properly.

Incorrect syntax results in errors and performance issues, while clear and consistent syntax ensures accurate results and maintainable code.

🎯 In this guide, you’ll learn:

  • Basic structure of SQL statements
  • Syntax for SELECT, INSERT, UPDATE, DELETE
  • Use of semicolons, comments, and indentation
  • SQL keywords, case sensitivity, and formatting rules

βœ… 1. General SQL Statement Structure

SQL_KEYWORD column1, column2
FROM table_name
WHERE condition;

βœ… SQL is case-insensitive, but uppercase for keywords improves readability.


πŸ“€ 2. SELECT Statement Syntax

SELECT column1, column2
FROM table_name
WHERE condition;

βœ… Retrieves data from one or more columns in a table.

πŸ’‘ Tip: Use * to select all columns.


πŸ“ 3. INSERT Statement Syntax

INSERT INTO table_name (column1, column2)
VALUES (value1, value2);

βœ… Adds new data to a table.

⚠️ Always match values with column order.


πŸ› οΈ 4. UPDATE Statement Syntax

UPDATE table_name
SET column1 = value1, column2 = value2
WHERE condition;

βœ… Modifies existing records.

⚠️ Use WHERE to avoid updating all rows.


❌ 5. DELETE Statement Syntax

DELETE FROM table_name
WHERE condition;

βœ… Removes specific records.

⚠️ Omitting WHERE deletes all data in the table.


🧾 6. SQL Syntax Rules & Conventions

Rule / ElementDescription
πŸ†Ž KeywordsUse uppercase for clarity (e.g., SELECT, WHERE)
; SemicolonTerminates statements in SQL (especially in multi-line scripts)
πŸ’¬ CommentsSingle-line: -- comment, Multi-line: /* comment */
πŸ“ WhitespaceIgnored by SQL but helps with readability
πŸ†š Case SensitivitySQL keywords are not case-sensitive, but identifiers may be, depending on the RDBMS

πŸ“ƒ Complete List of SQL Syntax (Commands + Clauses)


πŸ—οΈ Data Definition Language (DDL) – Define & Modify Structure

CommandSyntax
CREATE TABLECREATE TABLE table_name (column1 datatype, column2 datatype);
ALTER TABLEALTER TABLE table_name ADD column_name datatype;
DROP TABLEDROP TABLE table_name;
TRUNCATE TABLETRUNCATE TABLE table_name;
RENAME TABLERENAME TABLE old_name TO new_name;
CREATE DATABASECREATE DATABASE db_name;
DROP DATABASEDROP DATABASE db_name;

✍️ Data Manipulation Language (DML) – Manage Table Data

CommandSyntax
INSERT INTOINSERT INTO table_name (col1, col2) VALUES (val1, val2);
UPDATEUPDATE table_name SET col1 = val1 WHERE condition;
DELETEDELETE FROM table_name WHERE condition;

πŸ” Data Query Language (DQL) – Retrieve Data

CommandSyntax
SELECTSELECT column1, column2 FROM table_name WHERE condition;

πŸ” Data Control Language (DCL) – Permissions & Access

CommandSyntax
GRANTGRANT SELECT, INSERT ON table_name TO user;
REVOKEREVOKE SELECT, INSERT ON table_name FROM user;

πŸ” Transaction Control Language (TCL) – Manage Transactions

CommandSyntax
COMMITCOMMIT;
ROLLBACKROLLBACK;
SAVEPOINTSAVEPOINT savepoint_name;
RELEASE SAVEPOINTRELEASE SAVEPOINT savepoint_name;
SET TRANSACTION`SET TRANSACTION [READ ONLY

πŸ“Œ Clauses Used in SQL Queries

ClausePurpose
WHEREFilters rows based on conditions
ORDER BYSorts results ascending/descending
GROUP BYGroups results for aggregation
HAVINGFilters groups (used with GROUP BY)
DISTINCTRemoves duplicate rows
LIMIT / TOPRestricts number of returned rows
OFFSETSkips rows before returning results
ASCreates aliases for columns/tables
IN / BETWEEN / LIKEConditional filters
IS NULL / IS NOT NULLChecks for null values
EXISTSChecks if subquery returns rows
UNION / UNION ALLCombines results from multiple queries
INTERSECT / EXCEPTFinds common or exclusive rows
CASEImplements if/else logic in queries

πŸ”— JOIN Types

Join TypeSyntax
INNER JOINSELECT * FROM A INNER JOIN B ON A.id = B.id;
LEFT JOINSELECT * FROM A LEFT JOIN B ON A.id = B.id;
RIGHT JOINSELECT * FROM A RIGHT JOIN B ON A.id = B.id;
FULL OUTER JOINSELECT * FROM A FULL OUTER JOIN B ON A.id = B.id;
CROSS JOINSELECT * FROM A CROSS JOIN B;
SELF JOINSELECT A.name, B.name FROM employees A, employees B WHERE A.manager_id = B.id;

πŸ“ˆ Aggregate Functions Syntax

FunctionExample
COUNT()SELECT COUNT(*) FROM employees;
SUM()SELECT SUM(salary) FROM employees;
AVG()SELECT AVG(age) FROM students;
MAX() / MIN()SELECT MAX(price), MIN(price) FROM products;

πŸ”’ Operators in SQL Syntax

TypeOperators
Arithmetic+, -, *, /, %
Comparison=, !=, <>, <, >, <=, >=
LogicalAND, OR, NOT
Bitwise&, `

πŸ“˜ Best Practices

βœ… Do This❌ Avoid This
Use consistent formattingMixing upper and lowercase randomly
Comment complex queriesWriting long queries without notes
Write keywords in uppercaseLowercasing everything
Use proper indentationWriting queries on a single line

πŸ“Œ Summary – Recap & Next Steps

Understanding SQL syntax is the first step in writing clean, error-free queries. Whether you’re fetching, inserting, or modifying data, proper syntax ensures your database runs smoothly.

πŸ” Key Takeaways:

  • SQL has a simple and readable syntax, based on English
  • Each statement ends with a semicolon
  • Formatting improves maintainability and teamwork
  • Case sensitivity depends on your SQL engine (MySQL, Oracle, PostgreSQL, etc.)

βš™οΈ Real-World Relevance:
Clean SQL syntax helps avoid bugs, optimize performance, and collaborate effectively in data-driven teams.

❓ FAQ – SQL Syntax Explained

❓ Do SQL statements end with a semicolon?

βœ… Yes, a semicolon ; is used to terminate statements, especially when running multiple queries in a script.

❓ Are SQL keywords case-sensitive?

βœ… No. SELECT, select, and SeLeCt are treated the same. But table/column names may be case-sensitive, depending on your DBMS.

❓ What happens if I omit the WHERE clause in UPDATE or DELETE?

⚠️ All rows will be updated or deleted. Always double-check before running such queries.

❓ Can I write SQL in a single line?

βœ… Yes, but it’s not recommended for readability. Break complex statements into multiple lines.

❓ How do I write comments in SQL?

βœ… Use -- for single-line or /* ... */ for multi-line comments.


Share Now :

Leave a Reply

Your email address will not be published. Required fields are marked *

Share

🧾 SQL Syntax

Or Copy Link

CONTENTS
Scroll to Top