Experiment No.
2
Title: Use DDL Statements to Crete, Alter, Drop, Rename, Truncate Tables
Aim:
To understand and practice the use of SQL Data Definition Language (DDL) statements for
creating, modifying, and managing relational database tables.
Objectives:
To learn the syntax and usage of SQL DDL commands.
To create database tables using the CREATE statement.
To modify table structure using the ALTER statement.
To delete entire tables using the DROP statement.
To reset table data using the TRUNCATE command.
To change the name of tables using the RENAME command.
To perform hands-on activities and understand the impact of each command.
Theory:
What is DDL?
Data Definition Language (DDL) is a subset of SQL used to define and manage the structure
of database objects such as tables, indexes, and schemas.
Common DDL Commands:
Command Description
CREATE Creates a new table or other database object
ALTER Modifies existing table structure (add, drop, or modify column)
DROP Permanently deletes a table or database structure
RENAME Renames a table or column
TRUNCATE Removes all data from a table but not the table itself
Step-by-Step Execution with Example:
🔹 1. CREATE TABLE
a) Create a table to store lab equipment details:
CREATE TABLE LabEquipment (
EquipmentID INT PRIMARY KEY,
EquipmentName VARCHAR(100),
LabName VARCHAR(100),
PurchaseDate DATE,
Condition VARCHAR(50)
);
b) Create a table to store faculty information:
sql
CREATE TABLE Faculty (
FacultyID INT PRIMARY KEY,
Name VARCHAR(100),
Qualification VARCHAR(50),
Department VARCHAR(50),
PhoneNo VARCHAR(15)
);
🔹 2. ALTER TABLE
Add a column for SupplierName to the LabEquipment table:
sql
ALTER TABLE LabEquipment
ADD SupplierName VARCHAR(100);
🔹 3. RENAME TABLE
Rename the Faculty table to MechanicalFaculty:
sql
RENAME TABLE Faculty TO MechanicalFaculty;
Note: On some databases like Oracle:
sql
ALTER TABLE Faculty RENAME TO MechanicalFaculty;
🔹 4. TRUNCATE TABLE
Remove all records from the LabEquipment table without deleting its structure:
sql
TRUNCATE TABLE LabEquipment;
🔹 5. DROP TABLE
Delete the MechanicalFaculty table permanently:
sql
DROP TABLE MechanicalFaculty;
Expected Outcomes:
Upon completing this lab, students will be able to:
✅ Create relational tables with appropriate data types and constraints.
✅ Modify existing table structure using the ALTER statement.
✅ Rename and drop tables effectively and safely.
✅ Understand the difference between TRUNCATE and DELETE.
✅ Apply these DDL commands while working with real-world database schemas.