Chapter 01
Introduction to SQL
5 topics · 1 sections · beginner-friendly study notes · Updated
SQL stands for Structured Query Language.
It is the standard language used to store, read, change and delete data in a relational database.
Think of it as the language you use to talk to a database, like asking the college office for a list of students.
Almost every app stores data in a database, and most databases understand SQL.
Learning SQL is the first step for developers, testers, analysts and data scientists.
Websites, banking apps, school and college portals, shopping sites and reports all use SQL to keep and fetch data.
What is SQL
SQL (Structured Query Language) is a standard language used to create, read, update and delete data stored in a relational database.
In short: SQL is the language we use to talk to a database. We write a short command, and the database gives us the answer.
Think about it
Before SQL, every database had its own way of asking for data. A common language made it easy to learn once and use everywhere. Imagine a college office with a big register of students. SQL is like the polite request you give the clerk: "Show me all students of the CSE department."
A relational database keeps data in tables.
Each table has columns (fields) and rows (records).
SQL lets us work with these tables without worrying how the data is stored on disk.
SQL is declarative.
We say WHAT we want, not HOW to get it.
For example, we say "give me all students from Delhi" and the database finds the best way.
SQL became an ANSI and ISO standard, so the basic commands are the same in MySQL, PostgreSQL, Oracle, SQL Server and SQLite.
Each product adds a few extra features, called dialects.
Key points
- Database: An organised collection of data, like a digital cupboard of registers.
- Table: A grid of rows and columns that stores one type of data, such as students.
- Row (record): One entry in a table, such as one student.
- Column (field): One property of every row, such as the name.
- Query: A SQL command that asks the database a question.
- SQL is not case sensitive for keywords. SELECT and select work the same.
- Most databases end a statement with a semicolon (;).
- SQL is a language, not a database product.
Example
CodeFirst SQL query: -- A tiny first query on a student table SELECT name, city FROM student;
SQL vs DBMS
A DBMS (Database Management System) is the software that stores and manages data. SQL is the language we use to give instructions to a relational DBMS (RDBMS).
In short: DBMS is the machine. SQL is the language we use to operate the machine.
Think about it
Beginners often mix these two words. Knowing the difference helps in interviews and in choosing tools. A car and the steering wheel. The car (DBMS) does the work. The steering wheel and pedals (SQL) let you control it.
Examples of DBMS software are MySQL, PostgreSQL, Oracle Database, Microsoft SQL Server and SQLite.
They look after storage, security, backup, users and speed.
SQL is just the set of commands those systems understand.
A DBMS can exist without SQL.
For example, MongoDB is a NoSQL DBMS and uses its own query style.
But a relational DBMS (RDBMS) almost always uses SQL.
So when people say "I use MySQL", they mean the software.
When they say "I wrote a SQL query", they mean the language.
Key points
- RDBMS: Relational DBMS. It stores data in tables, like MySQL or Oracle.
- NoSQL: Databases that do not use tables, such as MongoDB.
- Dialect: A small variation of SQL used by one product.
- SQL = language. DBMS = software.
- MySQL, Oracle, PostgreSQL are DBMS products, not languages.
- One SQL skill works on many DBMS products with small changes.
Example
CodeSame query on many databases: -- Same SQL idea, different DBMS products -- MySQL, PostgreSQL, Oracle and SQL Server all accept: SELECT * FROM student;
How SQL Works
When we send a SQL query, the database parses it, checks it, plans the best way to run it, executes it and returns the result.
In short: You type a query. The database reads it, thinks about the fastest path, does the work and shows you the rows.
Think about it
Knowing these steps explains why errors appear (syntax error, table not found) and why some queries are slower than others. Ordering food. You tell the waiter your order (query). The kitchen checks the menu (parser), plans the cooking (optimizer), cooks (engine) and the waiter brings the dish (result).
Step 1: The client (an app or a tool) sends the SQL text to the server.
Step 2: The parser checks the spelling and grammar (syntax).
Step 3: The checker confirms that the tables and columns exist and you have permission.
Step 4: The optimizer chooses the fastest plan, such as using an index instead of reading the whole table.
Step 5: The execution engine reads or changes data using the storage engine.
Step 6: The result set is sent back.
For commands like INSERT or UPDATE, the database returns a message such as "3 rows affected".
Key points
- Parser: Checks if the SQL text is written correctly.
- Optimizer: Chooses the fastest way to run the query.
- Execution engine: Actually reads or changes the data.
- Result set: The rows returned by a SELECT query.
- A syntax error means the parser could not understand your query.
- The optimizer can choose different plans for the same query.
Example
CodeSee the query plan: -- Most databases can show the plan the optimizer picked EXPLAIN SELECT name FROM student WHERE city = "Delhi";
Types of SQL Commands
SQL commands are grouped by purpose: DDL (Data Definition Language), DML (Data Manipulation Language), DQL (Data Query Language), DCL (Data Control Language) and TCL (Transaction Control Language).
In short: Some commands build the tables, some change the data, some read the data, some give permissions and some save or undo work.
Think about it
Interviews and exams ask for these groups very often. They also help you remember which command does what. In a college office: DDL builds new registers, DML writes in them, DQL reads them, DCL gives keys to staff, TCL confirms or cancels a batch of entries.
DDL: CREATE, ALTER, DROP, TRUNCATE.
They change the structure of the database.
They change the data inside tables.
DQL: SELECT.
It reads data.
Some books put SELECT inside DML.
DCL: GRANT, REVOKE.
They give or take away permissions.
TCL: COMMIT, ROLLBACK, SAVEPOINT.
They control transactions, which are groups of changes done together.
Key points
- DDL: Defines structure: CREATE, ALTER, DROP, TRUNCATE.
- DML: Changes data: INSERT, UPDATE, DELETE.
- DQL: Reads data: SELECT.
- DCL: Controls access: GRANT, REVOKE.
- TCL: Controls transactions: COMMIT, ROLLBACK, SAVEPOINT.
- DDL commands usually save automatically in most databases.
- DML changes can be undone with ROLLBACK until you COMMIT.
Example
CodeOne command from each group: -- DDL: build a table CREATE TABLE student (roll_no INT, name VARCHAR(50)); -- DML: add data INSERT INTO student VALUES (1, "Asha"); -- DQL: read data SELECT * FROM student; -- DCL: give permission GRANT SELECT ON student TO clerk; -- TCL: save work COMMIT;
Advantages of SQL
SQL is popular because it is easy to learn, fast, standard, powerful and works with almost every database.
In short: SQL reads almost like English, so even beginners can write useful queries on day one.
Think about it
These points are the standard answer to "Why do we use SQL?" in viva and interviews. Like using a calculator. One tool, simple buttons, and the result is quick and correct.
Easy to learn: commands such as SELECT and INSERT are plain English words.
Fast: databases can handle millions of rows in a blink using indexes.
Standard: ANSI and ISO rules keep the basics the same everywhere.
Powerful: with joins, grouping and subqueries we can answer complex questions.
No coding skill needed to read data: analysts use SQL without being programmers.
Secure: permissions control who can see or change data.
Portable: the same ideas work on MySQL, Oracle, PostgreSQL and more.
Works with many languages: Java, Python, PHP and JavaScript can all send SQL to a database.
Key points
- Portable: Works on many database products with little change.
- Scalable: Can handle small and very large data.
- Advantage 1: Simple and English-like.
- Advantage 2: Fast data retrieval.
- Advantage 3: Standard language for all RDBMS.
- Advantage 4: Secure access with permissions.
- Advantage 5: Handles huge data and many users.
Read more
Example
CodeReadable query: -- Simple English-like query to find the top three marks SELECT name, marks FROM student ORDER BY marks DESC LIMIT 3;
Solved examples
Classify each command as DDL, DML, DQL, DCL or TCL: CREATE, INSERT, SELECT, GRANT, ROLLBACK.
- Commands: CREATE, INSERT, SELECT, GRANT, ROLLBACK
Group of each command
Formula Applied:—Approach note: Ask one question: does it change structure, change data, read data, control access or control a transaction?
Write a first complete session: create a student table, add two students and show them.
- Columns: roll_no, name, city
SQL statements
Formula Applied:—Approach note: First build the table, then add data, then read the data. This order always works.
A friend says "I installed SQL on my laptop". What is wrong with this sentence?
- SQL is a language
Correct statement
Formula Applied:—Approach note: Language = SQL. Software = MySQL, Oracle, PostgreSQL, SQL Server.
Which SQL group does each belong to: UPDATE, DROP, REVOKE, COMMIT?
Four classifications
Formula Applied:—Approach note: DDL = structure, DML = data, DCL = access, TCL = transactions.
Real-world applications
Using Introduction to SQL in real projects
Websites, banking apps, school and college portals, shopping sites and reports all use SQL to keep and fetch data.
Common mistakes
❌ Myth: SQL and MySQL are the same thing.
Why this is wrong: The names look alike, so people mix them up.
✅ Verified Truth: SQL is the language. MySQL is one database software that understands SQL.
⚠️ Exam Tip: Write "MySQL is an RDBMS that uses SQL".
❌ Myth: SQL is a programming language like Java.
Why this is wrong: SQL has commands and logic, so it feels like programming.
✅ Verified Truth: SQL is a declarative query language made for databases. It says what data we want, not how to loop to find it.
⚠️ Exam Tip: In viva, say "SQL is a domain-specific, declarative language".
❌ Myth: DROP and DELETE do the same job.
Why this is wrong: Both remove something.
✅ Verified Truth: DELETE removes rows. DROP removes the whole table or database with its structure.
⚠️ Exam Tip: DELETE is DML. DROP is DDL.
Revision notes
SQL stands for Structured Query Language. It is the standard language used to store, read, change and delete data in a relational database. Think of it as the language you use to talk to a database, like asking the college office for a list of students.
High-Yield Quick Revision Points
- SQL = Structured Query Language, used for relational databases.
- SQL is a language. MySQL, Oracle and PostgreSQL are DBMS software.
- Query steps: parse, check, optimize, execute, return result.
- DDL: CREATE, ALTER, DROP, TRUNCATE.
- DML: INSERT, UPDATE, DELETE. DQL: SELECT.
- DCL: GRANT, REVOKE. TCL: COMMIT, ROLLBACK, SAVEPOINT.
- Advantages: easy, fast, standard, secure, portable and powerful.
Practice questions
What does SQL stand for?
Which of these is a DBMS and not a language?
Which group does the CREATE TABLE command belong to?
Which command is used to give permission to a user?
Which step decides the fastest way to run a query?