0% found this document useful (0 votes)
11 views3 pages

Exp 2

This document outlines an experiment focused on using SQL Data Definition Language (DDL) statements to create, alter, drop, rename, and truncate database tables. It includes objectives, common DDL commands, step-by-step execution examples, and expected outcomes for students. The aim is to provide hands-on experience with DDL commands for managing relational database structures.

Uploaded by

smkodole06
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

Exp 2

This document outlines an experiment focused on using SQL Data Definition Language (DDL) statements to create, alter, drop, rename, and truncate database tables. It includes objectives, common DDL commands, step-by-step execution examples, and expected outcomes for students. The aim is to provide hands-on experience with DDL commands for managing relational database structures.

Uploaded by

smkodole06
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

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.

You might also like