Introduction to SQL Syntax and Command Structure

πŸ“Š Speak the language of databases

SQL (Structured Query Language) is the standard language used to communicate with relational databases like SQL Server, MySQL, and SQLite. Whether you’re building desktop apps, websites, or data-driven tools, SQL is the bridge between your code and the stored data.

In this guide, you’ll learn the basic syntax, command structure, and how to perform the most common SQL operations like querying, inserting, and filtering data.


πŸ“ What is SQL Used For?

  • πŸ“„ Creating and modifying databases and tables
  • πŸ“₯ Inserting new records
  • πŸ” Querying and filtering data
  • ✏️ Updating existing records
  • ❌ Deleting records
  • πŸ” Managing access and structure

🧱 SQL Syntax Basics

SQL commands follow a clear, readable structure, and are not case-sensitive (but best practice is to capitalise keywords):

SELECT column1, column2
FROM TableName
WHERE condition;

πŸ’‘ Statements always end with a semicolon (;).


πŸ”Ή SQL Statement Categories

CategoryPurposeExamples
DDLData Definition LanguageCREATE, ALTER, DROP
DMLData Manipulation LanguageSELECT, INSERT, UPDATE, DELETE
DCLData Control LanguageGRANT, REVOKE
TCLTransaction Control LanguageCOMMIT, ROLLBACK

For beginners, DML and DDL are your main focus.


πŸ“Œ Creating Tables

CREATE TABLE Customers (
CustomerID INT PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
Email VARCHAR(100),
Age INT
);

πŸ’‘ Each column has a name and a data type (like INT, VARCHAR, DATE, etc.)


πŸ“₯ Inserting Data

INSERT INTO Customers (CustomerID, FirstName, LastName, Email, Age)
VALUES (1, 'Alice', 'Smith', 'alice@example.com', 28);

You can add one row at a time or multiple:

INSERT INTO Customers VALUES 
(2, 'Bob', 'Jones', 'bob@example.com', 35),
(3, 'Clara', 'White', 'clara@example.com', 22);

πŸ” Reading Data – SELECT

The SELECT statement is the most commonly used command in SQL.

SELECT * FROM Customers;
SymbolMeaning
*Select all columns
WHEREAdd a filter condition
ORDER BYSort the results
LIMITLimit the number of rows

🎯 Examples:

SELECT FirstName, LastName FROM Customers
WHERE Age > 30
ORDER BY LastName ASC;
SELECT COUNT(*) FROM Customers WHERE Email LIKE '%@gmail.com';

✏️ Updating Data

UPDATE Customers
SET Age = 29
WHERE CustomerID = 1;

πŸ’‘ Always use WHERE to avoid updating every row!


❌ Deleting Data

DELETE FROM Customers
WHERE CustomerID = 3;

Without a WHERE clause, it would delete every row.


πŸ” Common Data Types

TypeDescription
INTWhole numbers
FLOATDecimal numbers
VARCHAR(n)Text up to n characters
DATEDate values (YYYY-MM-DD)
BOOLEANTrue/False

πŸ§ͺ Quick SQL Challenge

  1. Create a table called Books with:
    • BookID, Title, Author, Year, InStock (boolean)
  2. Insert three books into the table
  3. Select all books published after 2010
  4. Update the stock of one book to false
  5. Delete a book by BookID

🧠 Best Practices

βœ… Use capital letters for SQL keywords (SELECT, FROM, etc.)
βœ… Always include WHERE when updating or deleting
βœ… Use meaningful column names
βœ… Keep column types appropriate to the data
βœ… Format your queries for readability


πŸ“š Summary Table

CommandPurpose
SELECTRetrieve data from a table
INSERTAdd new data to a table
UPDATEModify existing data
DELETERemove data from a table
CREATE TABLEDefine a new table structure

πŸ”œ What’s Next?

SQL is a core skill in full-stack development β€” learning it well sets you up for APIs, web apps, reports, and more. Join our SQL Essentials course to further your understanding.