Font size
  • A-
  • A
  • A+
Site color
  • R
  • A
  • A
  • A
Skip to main content
Readepert
  • Home
  • Calendar
  • Course Categories
    Programming Languages AI, ML And Data Science
  • Exams
  • Results
  • Tutorials
  • Books
  • Colleges
  • Universities
  • Schools
  • Webstes
  • Software & Tools
  • Compilers & Practice Tools
  • More
You are currently using guest access
Log in
Readepert
Home Calendar Course Categories Collapse Expand
Programming Languages AI, ML And Data Science
Exams Results Tutorials Books Colleges Universities Schools Webstes Software & Tools Compilers & Practice Tools
Expand all Collapse all

Introduction to SQL

  1. Dashboard
  2. Courses
  3. Programming Languages
  4. SQL
  5. Module 1: Introduction to Databases And SQL
  6. Introduction to SQL
Completion requirements

1. πŸ”Ή What is SQL?

  • SQL stands for Structured Query Language.

  • It is the standard language used to communicate with databases.

  • SQL helps you:

    • Create databases and tables

    • Insert, update, and delete data

    • Query (search/filter) data

    • Control access (permissions)

    • Manage transactions

πŸ‘‰ In simple words: SQL is the language of databases.


2. πŸ”Ή Why Learn SQL?

  • Every business stores data (e-commerce, banking, education, social media).

  • SQL is used to organize and retrieve this data.

  • If you can speak SQL, you can β€œtalk to databases” like MySQL, PostgreSQL, SQL Server, Oracle, and SQLite.


3. πŸ”Ή Categories of SQL Commands

SQL commands are grouped into five main categories:


🟦 A. DDL (Data Definition Language)

  • Deals with structure of database objects (like tables, schemas).

  • Used to create, modify, or delete tables and databases.

Common Commands:

  • CREATE β†’ create a new table or database.

  • ALTER β†’ change structure (add/remove column).

  • DROP β†’ delete a table or database.

Example:

Β 
-- Create a table CREATE TABLE Employees ( EmployeeID INT PRIMARY KEY, Name VARCHAR(50), Salary DECIMAL(10,2) ); -- Add a new column ALTER TABLE Employees ADD Department VARCHAR(50); -- Delete the table DROP TABLE Employees;

🟩 B. DML (Data Manipulation Language)

  • Deals with data stored inside tables.

  • Used to insert, modify, or remove records.

Common Commands:

  • INSERT β†’ add data into a table.

  • UPDATE β†’ modify existing data.

  • DELETE β†’ remove data.

Example:

Β 
-- Insert data INSERT INTO Employees (EmployeeID, Name, Salary, Department) VALUES (101, 'John', 50000, 'HR'); -- Update salary UPDATE Employees SET Salary = 55000 WHERE EmployeeID = 101; -- Delete record DELETE FROM Employees WHERE EmployeeID = 101;

🟨 C. DCL (Data Control Language)

  • Deals with access rights and permissions.

  • Used to control who can access what in the database.

Common Commands:

  • GRANT β†’ give permission.

  • REVOKE β†’ take back permission.

Example:

Β 
-- Give permission to user GRANT SELECT, INSERT ON Employees TO user1; -- Revoke permission REVOKE INSERT ON Employees FROM user1;

πŸŸ₯ D. TCL (Transaction Control Language)

  • Deals with transactions (a group of SQL commands that run together).

  • Helps maintain data integrity.

Common Commands:

  • COMMIT β†’ save changes permanently.

  • ROLLBACK β†’ undo changes.

  • SAVEPOINT β†’ create a checkpoint to rollback partially.

Example:

Β 
-- Start transaction BEGIN; -- Insert new record INSERT INTO Employees (EmployeeID, Name, Salary, Department) VALUES (102, 'Alice', 70000, 'IT'); -- Save changes COMMIT; -- Or, rollback if something goes wrong ROLLBACK; -- Using savepoint SAVEPOINT sp1; UPDATE Employees SET Salary = 80000 WHERE EmployeeID = 102; ROLLBACK TO sp1;

🟧 (Optional) DQL (Data Query Language)

  • Some books/websites treat SELECT as a separate category (DQL).

  • Used only for retrieving data.

Example:

Β 
SELECT Name, Salary FROM Employees WHERE Department = 'IT';

4. πŸ“Š Summary Table

Category Full Form Purpose Examples
DDL Data Definition Language Defines structure CREATE, ALTER, DROP
DML Data Manipulation Language Manages data INSERT, UPDATE, DELETE
DCL Data Control Language Controls access GRANT, REVOKE
TCL Transaction Control Language Manages transactions COMMIT, ROLLBACK, SAVEPOINT
DQL Data Query Language Retrieves data SELECT

βœ… You now know:

  • What SQL is

  • Why it is important

  • The 4 (or 5) categories of SQL commands with examples

πŸ“˜ Introduction to SQL (with Real-World Use-Cases)


1. πŸ”Ή Banking System Example

A bank needs to manage customers, accounts, and transactions. Let’s see how each SQL category fits in.


🟦 A. DDL in Banking (Creating Database Structure)

πŸ‘‰ When a bank creates new systems, they define tables.

Β 
-- Create Accounts table CREATE TABLE Accounts ( AccountID INT PRIMARY KEY, CustomerName VARCHAR(50), AccountType VARCHAR(20), Balance DECIMAL(12,2) );

πŸ’‘ Use-case:

  • Create Accounts, Transactions, Loans tables.

  • Alter structure when rules change (e.g., add IFSC_Code).

  • Drop test tables after migration.


🟩 B. DML in Banking (Managing Customer Data)

πŸ‘‰ Once the structure is ready, banks insert and update customer details.

Β 
-- Add new customer account INSERT INTO Accounts (AccountID, CustomerName, AccountType, Balance) VALUES (101, 'Rahul Sharma', 'Savings', 25000); -- Update balance after deposit UPDATE Accounts SET Balance = Balance + 5000 WHERE AccountID = 101; -- Delete closed account DELETE FROM Accounts WHERE AccountID = 101;

πŸ’‘ Use-case:

  • Insert β†’ New account opening.

  • Update β†’ Deposit, withdrawal, or loan repayment.

  • Delete β†’ Account closure.


🟨 C. DCL in Banking (Access Permissions)

πŸ‘‰ A bank must control who can view/change data.

Β 
-- Grant access to accountant GRANT SELECT, UPDATE ON Accounts TO AccountantUser; -- Revoke update rights if role changes REVOKE UPDATE ON Accounts FROM AccountantUser;

πŸ’‘ Use-case:

  • Clerks β†’ Can only view accounts.

  • Managers β†’ Can view & update balances.

  • Auditors β†’ Can only read data, not change it.


πŸŸ₯ D. TCL in Banking (Transactions)

πŸ‘‰ Money transfers involve multiple steps. If any step fails, everything must be undone to maintain accuracy.

Β 
BEGIN; -- Deduct from sender UPDATE Accounts SET Balance = Balance - 10000 WHERE AccountID = 201; -- Add to receiver UPDATE Accounts SET Balance = Balance + 10000 WHERE AccountID = 202; -- Save transaction permanently COMMIT; -- If error occurs (like receiver account missing) ROLLBACK;

πŸ’‘ Use-case:

  • Ensure deposits and withdrawals happen together.

  • If system crashes midway β†’ rollback.

  • Savepoints used for partial rollbacks in large transactions.


2. πŸ”Ή E-Commerce Example

Imagine Amazon or Flipkart.

  • DDL β†’ Create tables: Products, Orders, Customers.

  • DML β†’ Insert new products, update stock after purchase, delete discontinued items.

  • DCL β†’ Grant access to customer service team for Orders, revoke admin rights after employee exit.

  • TCL β†’ Ensure product stock reduces only if payment is successful.

Example:

Β 
BEGIN; UPDATE Products SET Stock = Stock - 1 WHERE ProductID = 501; INSERT INTO Orders (OrderID, CustomerID, ProductID, Status) VALUES (1001, 301, 501, 'Confirmed'); COMMIT; -- if both succeed -- ROLLBACK; if stock < 0 or payment fails

3. πŸ”Ή University Example

For managing students and exams.

  • DDL β†’ Create Students, Courses, Results tables.

  • DML β†’ Insert new student records, update exam marks, delete graduated students.

  • DCL β†’ Grant professors access to marks, revoke access after semester ends.

  • TCL β†’ Ensure all marks for one exam update together or rollback.


4. πŸ“Š Quick Summary (Use-Cases at a Glance)

Category Banking Example E-Commerce Example University Example
DDL Create Accounts table Create Products table Create Students table
DML Insert deposits, update balance Update stock, insert orders Insert marks, update results
DCL Grant auditor read-only rights Grant CS team access Grant professor access
TCL Transfer money safely Payment + stock update Exam results update

βœ… Now you not only know theory + SQL commands, but also how banks, e-commerce, and universities actually use them.

This lesson is not ready to be taken.
Previous activity Understanding Tables, Rows, and Columns
Next activity 1. πŸ”Ή MySQL Installation

Contact us

Follow us

You are currently using guest access (Log in)
Data retention summary
Get the mobile app
Get the mobile app
Play Store App Store
Powered by Moodle

This theme was proudly developed by

Readexpert.com