1. SQL Basics

Database, DBMS, tables, SQL vs NoSQL and the 5 SQL command families, told as RegularMart's story.

1

🎯 Student AIM read this first · what you will learn on this page

Aim: By the end of this page you can explain what a database, a DBMS and an RDBMS are, read any table by its rows, columns and keys, and name the five families of SQL commands with an example of each.

Description: Every app you use, from banking to food delivery, keeps its data in a database, and SQL is the language we use to ask that database questions. This page tells RegularMart’s story: from a paper notebook and messy Excel copies to one safe database. You learn how a DBMS manages the data, how tables are linked by keys, how SQL and NoSQL differ, and what DDL, DML, DQL, DCL and TCL do, using the RegularMart employees, customers and orders tables, then practise with real-time scenarios.

🤔 Why learn SQL basics?

  • Company data is huge: lakhs of rows you cannot scroll through.
  • SQL asks the database a question and gets the answer in seconds.
  • Every later topic (SELECT, JOINs, GROUP BY) builds on these words.
  • DBMS vs RDBMS and DDL vs DML are first-round interview questions.

🌍 Where is it used?

  • 🏦 Banks: accounts and transactions → your statement.
  • 🍔 Food apps: orders, restaurants and delivery partners.
  • 🏥 Hospitals: patients, doctors and appointments.
  • 🛠️ Data engineers: ETL jobs, reports and dashboards, every day.
  • 📊 Analysts: answering business questions with queries.

📘 What you will learn

  • Life without a database: notebook → Excel copies → one safe database.
  • DBMS vs RDBMS: the manager software and tables linked by keys.
  • Table, row & column: cells, data types and the primary key.
  • SQL vs NoSQL: table rows vs JSON documents, and when to use each.
  • 5 command families: DDL, DML, DQL, DCL and TCL.
  • Recap: the whole page in a few lines you say aloud.

✅ After this page you can

  • Explain database, DBMS and RDBMS in one line each.
  • Point to a row, a column, a cell and the primary key of any table.
  • Say when to pick SQL and when NoSQL.
  • Sort any command into DDL, DML, DQL, DCL or TCL.
  • Answer the top 5 SQL basics interview questions below.

Before you start: nothing! This is the first page. Just know what an Excel sheet looks like.

🧠 All memory tricks

The 5 SQL command families on RegularMart's tables

FamilyFull formCommandsExample on our tablesReal result
🏗️ DDLData Definition LanguageCREATE, ALTER, DROP, TRUNCATECREATE TABLE customers (customer_id INT PRIMARY KEY, name VARCHAR(50), city VARCHAR(50));empty table, 3 columns, 0 rows
🛋️ DMLData Manipulation LanguageINSERT, UPDATE, DELETEINSERT INTO customers VALUES (1,'Arjun','Hyderabad'), … (5,'Rahul','Delhi');5 rows inserted
🔍 DQLData Query LanguageSELECTSELECT name, salary FROM employees WHERE salary > 50000;Priya 72000 · Anjali 65000 · Meena 58000
🔑 DCLData Control LanguageGRANT, REVOKEGRANT SELECT ON employees TO suresh;suresh can read employees, not change it
💾 TCLTransaction Control LanguageCOMMIT, ROLLBACK, SAVEPOINTBEGIN; UPDATE customers SET city = 'Pune'; ROLLBACK;5 rows changed, then all restored

🧪 Practice Lab try every query yourself · MySQL 8

Step 1 · Create the sample data

One script creates the 3 tables used on this page, with exactly the rows you saw in the animation.

-- RegularMart sample data for SQL Concepts · 1 · SQL Basics (MySQL 8)
CREATE TABLE employees (
  emp_id     INT PRIMARY KEY,
  name       VARCHAR(50),
  dept       VARCHAR(30),
  city       VARCHAR(30),
  salary     INT,
  join_date  DATE
);
INSERT INTO employees VALUES
(101,'Ravi','Sales','Hyderabad',45000,'2021-04-12'),
(102,'Priya','IT','Bengaluru',72000,'2019-08-01'),
(103,'Kiran','HR','Chennai',38000,'2022-01-17'),
(104,'Anjali','IT','Hyderabad',65000,'2020-11-23'),
(105,'Suresh','Sales','Pune',41000,'2023-06-05'),
(106,'Meena','Finance','Chennai',58000,'2018-03-14');

CREATE TABLE customers (
  customer_id INT PRIMARY KEY,
  name        VARCHAR(50),
  city        VARCHAR(50)
);
INSERT INTO customers VALUES
(1,'Arjun','Hyderabad'),
(2,'Divya','Chennai'),
(3,'Farhan','Mumbai'),
(4,'Lakshmi','Bengaluru'),
(5,'Rahul','Delhi');

CREATE TABLE orders (
  order_id    INT PRIMARY KEY,
  customer_id INT,            -- no foreign key on purpose: order 5005 has customer 6
  product     VARCHAR(30),
  amount      INT
);
INSERT INTO orders VALUES
(5001,1,'Mobile',15000),
(5002,2,'Laptop',55000),
(5003,1,'Headphones',2000),
(5004,4,'Watch',3500),
(5005,6,'Shoes',2500);

Works in MySQL 8 / MySQL Workbench. For an online playground, paste it into any MySQL 8 site.

Step 2 · Look at the data

employees 6 rows

emp_idnamedeptcitysalaryjoin_date
101RaviSalesHyderabad450002021-04-12
102PriyaITBengaluru720002019-08-01
103KiranHRChennai380002022-01-17
104AnjaliITHyderabad650002020-11-23
105SureshSalesPune410002023-06-05
106MeenaFinanceChennai580002018-03-14

customers 5 rows

customer_idnamecity
1ArjunHyderabad
2DivyaChennai
3FarhanMumbai
4LakshmiBengaluru
5RahulDelhi

orders 5 rows

order_idcustomer_idproductamount
50011Mobile15000
50022Laptop55000
50031Headphones2000
50044Watch3500
50056Shoes2500

Step 3 · Practice questions real-time scenarios · easy → hard

EasyDQL · SELECT *

Q1 📋 Your team lead says: “Show me everything in the employees table.”

💭 Hint: SELECT * means every column; no WHERE means every row.

EasyColumns

Q2 💼 Payroll only needs two columns: each employee’s name and salary.

💭 Hint: List the column names after SELECT, separated by commas.

EasyDQL · WHERE

Q3 💰 HR asks: who earns more than ₹50,000?

💭 Hint: WHERE keeps only the rows that pass the test.

EasyRows = records

Q4 🧮 The owner asks: how many records (rows) does each of our three tables have?

💭 Hint: COUNT(*) counts rows. One small SELECT per table, side by side.

MediumPrimary key

Q5 📞 A customer calls and gives her customer ID: 4. Pull up exactly that one customer.

💭 Hint: customer_id is the primary key: unique, so it finds exactly one row.

MediumRDBMS · linked tables

Q6 🔗 Arjun (customer 1) asks the support team: “What have I ordered?”

💭 Hint: orders carries customer_id, the key that links it to customers.

MediumDDL + DML

Q7 🏗️ The catalogue team needs a new table of product categories with three rows, and wants to see it.

💭 Hint: CREATE TABLE builds it (DDL), INSERT fills it (DML), SELECT reads it (DQL).

HardTCL · ROLLBACK

Q8 ↩️ Suresh ran an UPDATE without WHERE and every customer moved to Pune! Undo it before anyone sees, then check the cities.

💭 Hint: Inside a transaction, ROLLBACK throws away every change since BEGIN.

HardForeign key

Q9 ⛔ Finance found an order whose customer does not exist. Which order is it? (A FOREIGN KEY would have stopped it.)

💭 Hint: Look for orders whose customer_id is NOT IN the customers table.

Step 4 · Top 5 interview questions easy → tricky · click to reveal

Step 5 · Mini challenge: 🏆 Owner’s Monday snapshot

The owner wants one row for the Monday meeting: number of employees, the monthly salary bill, employees earning above ₹50,000, number of customers, number of orders and total sales.

💭 Hint: One SELECT with small sub-SELECTs side by side: COUNT(*), SUM(...) and a WHERE where needed.