Module 1: Introduction To SQL Topic 1: What Is A Database? Description Database
Module 1: Introduction To SQL Topic 1: What Is A Database? Description Database
Description
A Database is an organized collection of related data that is stored electronically so that it can be
easily accessed, managed, updated, and retrieved whenever required.
In simple terms, a database acts like a digital storage system where information is stored in an
organized manner. Instead of maintaining records on paper, organizations use databases to store
large amounts of information securely.
A database can contain multiple tables, and each table stores a specific type of information. For
example, a college database may have separate tables for students, faculty, departments, courses,
and attendance.
Real-World Examples
Banking System
Syntax
Full Query
-- Create a Database
CREATE DATABASE CollegeDB;
Practice Task
Task 1
Task 2
1
Create another database named HospitalDB.
Task 3
Description
DBMS (Database Management System) is software that allows users to create, store, retrieve,
update, and manage databases.
A DBMS acts as an interface between the user and the database. Instead of interacting directly with
the database files, users send commands to the DBMS, and it performs the required operations.
Data Storage
Data Retrieval
Data Security
Multi-user Access
Data Integrity
MySQL
Oracle Database
PostgreSQL
SQLite
MariaDB
Syntax
There is no dedicated SQL syntax for DBMS because it is software, not a command.
Full Query
2
CREATE DATABASE CompanyDB;
USE CompanyDB;
Practice Task
1. Install MySQL.
Description
RDBMS (Relational Database Management System) is a type of DBMS that stores data in the form of
tables.
An RDBMS organizes data into rows and columns and establishes relationships between tables using
Primary Keys and Foreign Keys.
For example, a college database may have separate tables for Students and Departments. These
tables are connected through a common column called a Foreign Key.
Features of RDBMS
Table-based storage
Data Integrity
3
Multi-user Support
Security
SQL Support
MySQL
Oracle
PostgreSQL
SQL Server
MariaDB
Syntax
Full Query
USE CollegeDB;
4
DepartmentID INT,
FOREIGN KEY (DepartmentID)
REFERENCES Department(DepartmentID)
);
Practice Task
Description
Although both DBMS and RDBMS are used to manage databases, RDBMS provides additional
features such as relationships, constraints, and better security.
DBMS RDBMS
5
Syntax
Practice Task
Description
SQL (Structured Query Language) is the standard language used to communicate with relational
databases.
Create databases
Create tables
Insert records
Retrieve records
Update records
Delete records
Control transactions
SQL is supported by almost every RDBMS, making it the most widely used language for database
management.
Applications of SQL
Banking Systems
Hospital Management
E-commerce Websites
6
Syntax
SQL_Command;
Examples:
Full Query
USE CollegeDB;
Output
103 Arun IT 19
7
Practice Task
o BookID
o BookName
o Author
o Price
4. Insert 5 records.
Description
SQL commands are classified into five categories based on the operation they perform on a
database. Understanding these categories is essential because every SQL statement belongs to one
of them.
1. DDL (Data Definition Language) – Used to define and modify the database structure.
2. DML (Data Manipulation Language) – Used to insert, update, and delete data.
4. DCL (Data Control Language) – Used to control user permissions and access.
Data Manipulation
DML Modifies data INSERT, UPDATE, DELETE
Language
Controls user
DCL Data Control Language GRANT, REVOKE
permissions
8
Category Full Form Purpose Common Commands
Transaction Control
TCL Manages transactions COMMIT, ROLLBACK, SAVEPOINT
Language
Syntax
DDL
DML
DQL
DCL
GRANT permission
ON table_name
TO user_name;
REVOKE permission
ON table_name
FROM user_name;
TCL
COMMIT;
9
ROLLBACK;
SAVEPOINT savepoint_name;
Full Query
-- Create Database
CREATE DATABASE CompanyDB;
-- Select Database
USE CompanyDB;
-- DDL
CREATE TABLE Employee(
EmployeeID INT PRIMARY KEY,
EmployeeName VARCHAR(50),
Department VARCHAR(30),
Salary DECIMAL(10,2)
);
-- DML
INSERT INTO Employee
VALUES
(101,'Rahul','IT',50000),
(102,'Priya','HR',45000);
UPDATE Employee
SET Salary = 55000
WHERE EmployeeID = 101;
-- DQL
SELECT * FROM Employee;
-- TCL
COMMIT;
Output
10
Practice Task
Task 1
Task 2
StudentID
StudentName
Department
Age
Task 3
Task 4
Task 5
Task 6
Task 7
Key Points
Interview Questions
11
3. Which SQL category does the SELECT command belong to?
Description
A Data Type defines the type of data that can be stored in a column of a table. Choosing the correct
data type helps improve storage efficiency, data accuracy, and query performance.
For example:
1. INT
Examples:
10
100
5000
StudentID INT
2. VARCHAR(n)
Examples:
Rahul
Computer Science
Chennai
StudentName VARCHAR(50)
12
3. CHAR(n)
If the specified length is not used, SQL automatically fills the remaining space with blank characters.
Example:
Gender CHAR(1)
Possible values:
M
F
4. DATE
Format:
YYYY-MM-DD
Example:
2026-06-28
DateOfBirth DATE
5. DECIMAL(p,s)
Example:
Salary DECIMAL(10,2)
Possible values
45000.50
150000.75
6. FLOAT
Example
Weight FLOAT
13
Possible values
65.5
72.85
7. BOOLEAN / BOOL
Possible values
TRUE
FALSE
Example
IsPlaced BOOLEAN
8. TEXT
Example
Address TEXT
Summary Table
14
Syntax
Full Query
-- Create Database
CREATE DATABASE CollegeDB;
-- Select Database
USE CollegeDB;
-- Insert Records
15
(102,
'Priya',
'F',
'2003-11-20',
'ECE',
9.10,
95.2,
FALSE,
'Coimbatore');
-- Display Records
Output
Practice Task
Task 1
Task 2
EmployeeID INT
EmployeeName VARCHAR(50)
Gender CHAR(1)
JoiningDate DATE
Department VARCHAR(30)
Salary DECIMAL(10,2)
Experience FLOAT
16
Column Name Data Type
IsPermanent BOOLEAN
Address TEXT
Task 3
Task 4
Task 5
Mobile Number
Salary
Date of Birth
Address
Employee Name
Department
Age
Key Points
Choose the correct data type based on the kind of values the column will store.
Proper data type selection improves storage efficiency and query performance.
17
Interview Questions
3. When would you use the DECIMAL data type instead of FLOAT?
Description
Naming Rules are guidelines used while creating database objects such as databases, tables,
columns, views, indexes, and constraints.
Following proper naming conventions makes the database easier to read, understand, and maintain,
especially when working on large projects or with multiple developers.
Database names, table names, and column names should begin with an alphabet.
✔ Correct
Student
Employee
Department
❌ Incorrect
123Student
1Employee
✔ Correct
StudentDetails
Student_Details
❌ Incorrect
Student Details
Employee Data
18
Rule 3: Use Meaningful Names
✔ Correct
Employee
EmployeeSalary
Department
StudentMarks
❌ Incorrect
ABC
XYZ
Table1
Data123
@
#
$
%
&
*
!
?
+
=
✔ Correct
Employee
Student_Name
❌ Incorrect
Employee#
Student@
Marks$
19
SELECT
FROM
WHERE
ORDER
GROUP
TABLE
DATABASE
INSERT
UPDATE
DELETE
Instead of
TABLE SELECT
Use
StudentDetails
EmployeeData
✔ Good
Employee
Department
StudentMarks
❌ Bad
EmployeeInformationManagementSystemData
Examples
StudentID
StudentName
DepartmentID
DepartmentName
20
Naming Convention Examples
Database Names
CollegeDB
LibraryDB
EmployeeDB
HospitalDB
Table Names
Student
Employee
Department
Course
Book
Column Names
StudentID
StudentName
Age
Salary
DepartmentID
JoiningDate
Syntax
USE CollegeDB;
21
StudentName VARCHAR(50),
Department VARCHAR(30)
);
Full Query
-- Create Database
-- Select Database
USE CollegeDB;
-- Display Tables
SHOW TABLES;
Output
+----------------+
| Tables_in_CollegeDB |
+----------------+
| Department |
| Student |
+----------------+
22
Best Practices
Prefix foreign keys with the referenced table name (e.g., DepartmentID in the Student table).
Practice Task
Task 1
Task 2
Student
Teacher
Subject
Classroom
Task 3
Example:
Student
StudentID
StudentName
Age
Gender
Teacher
TeacherID
TeacherName
23
SubjectName
Task 4
SHOW TABLES;
Task 5
Student
Employee123
Student Data
#Employee
Department_Name
SELECT
Marks
123College
Key Points
Interview Questions
24
3. Why should reserved keywords be avoided as object names?
This module covers the basic SQL commands used to create, view, select, and delete databases.
Description
The CREATE DATABASE statement is used to create a new database in the Database Management
System (DBMS).
A database acts as a container that stores tables, views, procedures, functions, and other database
objects.
Example
If you are developing a College Management System, the first step is to create a database named
CollegeDB. All related tables such as Student, Faculty, Department, and Course will be stored inside
this database.
Syntax
Full Query
SHOW DATABASES;
Output
+--------------------+
| Database |
+--------------------+
| CollegeDB |
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
25
Practice Task
Task 1
Task 2
Task 3
Task 4
Description
The SHOW DATABASES command displays all databases available in the MySQL server.
Syntax
SHOW DATABASES;
Full Query
SHOW DATABASES;
Output
+--------------------+
| Database |
+--------------------+
| CollegeDB |
| CompanyDB |
| SchoolDB |
| information_schema |
| mysql |
| performance_schema |
| sys |
+-----------------
26
Practice Task
o BankDB
o ShoppingDB
o RailwayDB
Description
Before creating tables or inserting records, SQL must know which database should be used.
Syntax
USE database_name;
Full Query
USE CollegeDB;
Example:
Practice Task
Task 1
Task 2
Task 3
27
Topic 4: DROP DATABASE
Description
Syntax
Full Query
SHOW DATABASES;
SHOW DATABASES;
Output
Before DROP
CollegeDB
EmployeeDB
TestDB
After DROP
CollegeDB
EmployeeDB
Practice Task
Task 1
Task 2
28
Task 3
Delete DemoDB.
Task 4
Display all databases again to verify that DemoDB has been removed.
Description
The following example demonstrates the complete workflow of creating, selecting, viewing, and
deleting a database.
Full Query
-- Create Database
-- Display Databases
SHOW DATABASES;
-- Select Database
USE CollegeDB;
-- Create Table
-- Display Tables
SHOW TABLES;
-- Delete Database
Practice Task
29
1. Create a database named UniversityDB.
3. Select UniversityDB.
o StudentID
o StudentName
o Department
Module 2 Summary
Command Purpose
In this module, you will learn how to create, view, modify, rename, empty, and delete tables. Tables
are the most important objects in a database because they store the actual data.
Description
The CREATE TABLE statement is used to create a new table inside a database.
30
1. A database must already exist.
Syntax
Full Query
-- Create Database
-- Select Database
USE CollegeDB;
SHOW TABLES;
Output
+--------------------+
| Tables_in_CollegeDB|
+--------------------+
| Student |
+--------------------+
31
Practice Task
Task 1
Task 2
StudentID
StudentName
Department
Age
Task 3
Description
The SHOW TABLES statement displays all tables available in the currently selected database.
Syntax
SHOW TABLES;
Full Query
USE LibraryDB;
32
);
SHOW TABLES;
Output
+------------------+
| Tables_in_LibraryDB |
+------------------+
| Books |
| Members |
+------------------+
Practice Task
o Employee
o Department
o Project
Description
It shows:
Column Name
Data Type
NULL Value
Key Information
Default Value
Extra Information
This command is useful when you want to know the table structure without opening the table.
Syntax
DESCRIBE table_name;
or
33
DESC table_name;
Full Query
USE CollegeDB;
DESC Student;
Output
+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| StudentID | int | YES | | NULL | |
| StudentName | varchar(50) | YES | | NULL | |
| Department | varchar(30) | YES | | NULL | |
| Age | int | YES | | NULL | |
+-------------+-------------+------+-----+---------+-------+
Practice Task
o DESC Employee;
o DESCRIBE Employee;
Description
The ALTER TABLE statement is used to modify the structure of an existing table.
Rename a column
Drop a column
34
Syntax
Add a Column
Modify a Column
Drop a Column
Full Query
USE CollegeDB;
-- Add a Column
-- Modify Column
-- Drop Column
DESC Student;
Output
+-------------+--------------+
| Field | Type |
+-------------+--------------+
| StudentID | int |
35
| StudentName | varchar(100) |
+-------------+--------------+
Practice Task
Description
The RENAME TABLE statement is used to change the name of an existing table.
Syntax
Full Query
USE CollegeDB;
SHOW TABLES;
Output
+--------------------+
| Tables_in_CollegeDB|
+--------------------+
| Students |
+--------------------+
36
Practice Task
2. Rename it to Employees.
Description
The TRUNCATE TABLE statement removes all records from a table but keeps the table structure
intact.
Use TRUNCATE when you want to empty a table quickly without deleting the table itself.
Syntax
Full Query
USE CollegeDB;
Output
Empty Set
37
Practice Task
2. Insert 5 records.
Description
The DROP TABLE statement permanently deletes a table from the database.
Syntax
Full Query
USE CollegeDB;
SHOW TABLES;
SHOW TABLES;
38
Output
Before DROP
Student
After DROP
Empty Set
Practice Task
Module 3 Summary
Command Purpose
39
6. Insert a few records (you'll learn INSERT in the next module).
40