Glossary/SQL Syntax, Keywords & DBMS vs RDBMS
SQL & Databases

SQL Syntax, Keywords & DBMS vs RDBMS

Understanding what SQL is, how it works, and the database systems that power it.


Definition

SQL (Structured Query Language) is the standard language for creating, querying, and managing relational databases. A DBMS (Database Management System) is any software that manages databases — including file-based systems. An RDBMS (Relational DBMS) specifically implements the relational model with tables, keys, and SQL. SQL is declarative: you state WHAT data you want, not HOW to get it. The database engine optimises execution automatically. SQL is case-insensitive for keywords but case-sensitive for data values in most systems.

DBMS vs RDBMS vs NoSQL

TypeData modelQuery languageExamples
DBMSAny (file, hierarchical, network)VariesIMS, ADABAS, early file systems
RDBMSTables with rows and columns — relational modelSQLPostgreSQL, MySQL, Oracle, SQL Server, SQLite
NoSQLDocuments, key-value, graph, wide-columnCustom (MongoDB Query, CQL, Gremlin)MongoDB, Redis, Cassandra, Neo4j, DynamoDB

SQL vs NoSQL — when to use which

Use SQL/RDBMS when: data is structured and relational, strong consistency is required, complex joins and transactions are needed, schema is stable. Use NoSQL when: data is unstructured or semi-structured (JSON, logs), horizontal scaling is critical, schema changes frequently, low-latency key-value lookup is the primary operation.

SQL statement categories

CategoryFull nameCommandsPurpose
DDLData Definition LanguageCREATE, ALTER, DROP, TRUNCATE, RENAMEDefine and modify database structure (schema)
DMLData Manipulation LanguageINSERT, UPDATE, DELETEAdd, change, remove data rows
DQLData Query LanguageSELECTRetrieve data (often grouped under DML)
DCLData Control LanguageGRANT, REVOKEManage user permissions and access rights
TCLTransaction Control LanguageCOMMIT, ROLLBACK, SAVEPOINTManage transaction boundaries

SQL syntax rules and conventions

SQL syntax: keywords, identifiers, comments, formatting

-- Single-line comment
/* Multi-line
   comment */

-- SQL is case-INSENSITIVE for keywords:
-- SELECT = select = Select = sElEcT (all equivalent)
-- But data values ARE case-sensitive:
-- WHERE Name = 'Ravi'  ≠  WHERE Name = 'ravi'

-- Basic statement structure:
SELECT column1, column2     -- Columns to retrieve
FROM   table_name           -- Source table
WHERE  condition            -- Filter rows (optional)
ORDER BY column1 ASC;       -- Sort result (optional)
-- Every SQL statement ends with semicolon (;)

-- Identifier quoting (for reserved words or special chars):
SELECT "select", "my-column", "Table Name"   -- PostgreSQL/standard
FROM   [my table]                            -- SQL Server
FROM   `my table`;                           -- MySQL

-- String literals use single quotes (ANSI standard):
WHERE Name = 'Ravi Kumar'    -- Correct
WHERE Name = "Ravi Kumar"    -- Non-standard (works in MySQL, not Oracle/PostgreSQL)

-- NULL is not a value — use IS NULL, not = NULL:
WHERE DeptID IS NULL      -- Correct
WHERE DeptID = NULL       -- ALWAYS FALSE (NULL != NULL in SQL)

-- Aliases
SELECT Name AS FullName, Salary * 12 AS AnnualSalary FROM Employee;
SELECT Name FullName FROM Employee;   -- AS is optional

The SELECT statement — anatomy and execution order

Full SELECT anatomy with all optional clauses

-- Written order:      Logical execution order:
-- 1. SELECT           5. SELECT (choose columns, compute expressions)
-- 2. FROM             1. FROM (identify source tables)
-- 3. JOIN             1. JOIN (combine tables)
-- 4. WHERE            2. WHERE (filter rows)
-- 5. GROUP BY         3. GROUP BY (form groups)
-- 6. HAVING           4. HAVING (filter groups)
-- 7. ORDER BY         6. ORDER BY (sort)
-- 8. LIMIT            7. LIMIT/OFFSET (paginate)

-- Full example showing all clauses:
SELECT DISTINCT           -- Remove duplicate output rows
    d.DeptName,
    COUNT(e.EmpID)   AS HeadCount,
    AVG(e.Salary)    AS AvgSalary,
    MAX(e.Salary)    AS TopSalary
FROM Employee e
INNER JOIN Department d ON e.DeptID = d.DeptID
WHERE e.Status = 'Active'
  AND e.JoinDate > '2020-01-01'
GROUP BY d.DeptName
HAVING COUNT(e.EmpID) > 5
ORDER BY AvgSalary DESC
LIMIT 10 OFFSET 0;        -- First page of 10 results

-- DISTINCT vs GROUP BY:
SELECT DISTINCT DeptID FROM Employee;      -- Unique dept values
SELECT DeptID, COUNT(*) FROM Employee GROUP BY DeptID;  -- Unique + counts

Why execution order matters

Because SELECT is executed in step 5, you CANNOT reference a SELECT alias in WHERE (step 2 runs before step 5). Example: SELECT Salary * 12 AS Annual ... WHERE Annual > 100000 FAILS. Use WHERE Salary * 12 > 100000 instead. However, you CAN use SELECT aliases in ORDER BY (runs after SELECT).

Practice questions

  1. Can you use a SELECT alias in the WHERE clause? (Answer: No — WHERE executes before SELECT in the logical order. Use the full expression in WHERE. You can use aliases in ORDER BY and HAVING (some DBMS allow it in HAVING).)
  2. What is the difference between DBMS and RDBMS? (Answer: DBMS is any database management software. RDBMS specifically implements the relational model — tables, rows, columns, SQL, and referential integrity. All RDBMS are DBMS but not all DBMS are RDBMS.)
  3. Why does WHERE Name = NULL never return any rows? (Answer: In SQL, NULL represents unknown. NULL = NULL evaluates to UNKNOWN (not TRUE). Use IS NULL or IS NOT NULL — these are the only operators that handle NULL correctly.)
  4. TRUNCATE vs DROP vs DELETE — key differences: (Answer: DROP removes table structure + data. TRUNCATE removes all rows, keeps structure, minimal logging, fast, no WHERE clause. DELETE removes specific rows, fully logged, supports WHERE, can be rolled back.)
  5. SQL is declarative. What does this mean? (Answer: You specify WHAT result you want, not HOW to compute it. The database query optimiser decides the execution plan. Compare to procedural code where you write step-by-step instructions.)

On LumiChats

LumiChats can explain any SQL concept, write queries for any scenario, and debug SQL errors. Try: 'Why is my WHERE clause not working with a NULL check?' or 'Explain the difference between TRUNCATE and DELETE with examples.'

Try it free

Try LumiChats for ₹69

39+ AI models. Study Mode with page-locked answers. Agent Mode with code execution. Pay only on days you use it.

Get Started — ₹69/day

Related Terms

4 terms