0% found this document useful (0 votes)
29 views40 pages

DBMS LAB final

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

DBMS LAB final

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

[Approved by AICTE, Govt. of India & Affiliated to Dr.

APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

G.L. BAJAJ INSTITUTE OF TECHNOLOGY & MANAGEMENT,


GREATER NOIDA

Database Management System Lab


(BCS-551)

LAB MANUAL
ACADEMIC SESSION 2024-25(ODD SEM)
NAME: MADHURENDRA KUMAR
ROLL NO: 2201921530096
COURSE: B. TECH (CSEAIML)
SEM: V

Dept. of Computer Science & Engineering (AIML)

G. L. BAJAJ INSTITUTE OF TECHNOLOGY AND MANAGEMENT


Plot no. 2, Knowledge Park III, Gr. Noida

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

INDEX

Date of Date of
S. No. List of Programs Signature
Experiment Submission
1. Installing Oracle/ MYSQL

Creating Entity-Relationship
2.
Diagram using case tools.
3. Writing SQL statements Using
ORACLE /MYSQL:
a) Writing basic SQL SELECT
statements.
b) Restricting and sorting data.

c) Displaying data from multiple


tables
d) Aggregating data using group
function.
e) Manipulating data.

f) Creating and managing tables

4. Subqueries/Nested queries and


constraints and view
5. Creating cursor
6. Creating procedure and functions
7. Creating packages and triggers
8. Normalization
9. Design and implementation of
Library Information System
10. Design and implementation of
Student Information System
11. Automatic Backup of Files and
Recovery of Files

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

12. Mini project (Design &


Development of Data and
Application :
Hotel Management System

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

EXPERIMENT NO. 1

Objective: Installing MYSQL.


Code with Output:
Download MySQL Installer

If you want to install MySQL on Windows, you can use the MySQL Installer. The MySQL
Installer provides you with an easy-to-use wizard that helps you to install MySQL with the
following main products:

● MySQL Server
● MySQL Workbench
● MySQL Shell
● MySQL Documentation
● All Available Connectors

To download the MySQL installer, go to the following


link http://dev.mysql.com/downloads/installer/.

We’ll use the MySQL Installer 8.0.34 to install the MySQL Server and related products such
as MySQL Workbench and MySQL Shell.
Install MySQL Server & related products using MySQL Installer

To install MySQL using the MySQL installer, double-click on the MySQL Installer file and
follow the steps below:

Step 1: Choosing a setup type

In this step, you need to choose the setup type that suits your use case. For tutorial purposes,
you can select the last option which is Custom setup type:

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

Step 2. Selecting products

Since we chose the Custom setup type, the MySQL Installer displays available products for us
to select to install.

We’ll install the following products:

● MySQL Server – This is the MySQL Database Server.


● MySQL Workbench – This is the client tool for interacting with the MySQL Database Server
via GUI.
● MySQL Shell – This is an interactive Javascript, Python, or SQL interface supporting
development and administration for the MySQL Server.

To select these products, you click the + icon on the left pane, select the product, and click the
right arrow button.
Here are the paths to the selected products:

● MySQL Servers > MySQL Server > MySQL Server 8.0 > MySQL Server 8.0.34 – x64
● Applications > MySQL Workbench > MySQL Workbench 8.0 > MySQL Workbench 8.0.34
– X64
● Applications > MySQL Shell > MySQL Shell 8.0 > MySQL Shell 8.0.34 – X64

Once you select the products, you click the Next button to continue.

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

Step 3. Downloading the selected products

The MySQL Installer will download the selected products from the internet. Please ensure you
have an active internet connection and wait for a few minutes for the download to complete.

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

After the download is complete, click the Execute button to start the installation.

Step 4. Installing the selected products

The MySQL Installer will install the selected products and this process may some time.

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

After the installation is complete, click the Next button to proceed to the Product
Configuration.

Step 5. Configuring the MySQL Server

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

In this step, configure the MySQL Server. Choose the Development Computer for the server
configuration type, leave the other options as they are, and click the Next button.

Step 6. Choosing an authentication method

It’s recommended to use strong password encryption for authentication, which is the first
option.

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

Step 7. Entering a password for the root account

Enter a secure password for the root account, which has full administrative privileges.
Be sure to store it safely and use it for connecting to the MySQL Server in the future.

Step 8. Configuring MySQL Server as a Windows Service

In this step, you can configure the MySQL Server as a Windows service, specify a service
name, and choose whether to start the MySQL Server during the operating system startup.

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

Step 9. Granting file permissions

In this step, you grant permission to MySQL to access the data directory.

Step 10. Displaying the selected configuration

The MySQL Installer displays a window with the configuration steps. Click the Execute button
to apply the configuration.

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

Step 11. Completing configuration

After applying the configuration, the MySQL Installer displays the following window to
indicate whether the MySQL Server has been configured successfully.

After completing the configuration, click the Next button to confirm and finish.

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

Step 12. Completing installation

The MySQL Installer displays a window to notify you that the installation is complete. Click
the Finish button to close the installer.

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

EXPERIMENT NO. 2

Objective : Creating Entity-Relationship Diagram using case tools.

Theory :

Entity Relationship Diagram

An Entity-Relationship Diagram is a graphical representation of entities and their


relationships within a system. It is widely used in database design to visualize the structure
and interconnections of the database components.

Components of ER Diagram

1. Entity
• Represents a real-world object or concept with distinct properties (attributes).
• Depicted as a rectangle.
2. Attribute
• Represents properties or characteristics of an entity or a relationship.
• Depicted as an oval connected to the entity or relationship.
3. Relationship
• Represents associations between entities.
• Depicted as a diamond.

Entity Attribute Relation

Steps :

Open MySQL Workbench

• Launch MySQL Workbench. Ensure that you have a running MySQL instance (it can
be a local or remote server).

Create a New Model

• File -> New Model: This opens up a new workspace where you will be able to create
your ER diagram.

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

• A blank diagram will open in a new tab within MySQL Workbench where you can
add your tables and relationships.

Add Tables (Entities) to Your Model

• Add Table: On the left side of MySQL Workbench, you'll see the "EER Diagram"
(Entity-Relationship Diagram) panel with an "Add Table" button.
• Click Add Table to create a new table (entity).
• A window pops up where you can define the table’s name (e.g., Student,
Department, Faculty).

Define Relationships Between Entities

• After creating your entities, you need to define relationships between them. Use the
Relationship tool for this.
• Add Relationship: Click on the "Place a Relationship" button from the vertical
toolbar (the button with a diamond-shaped icon).
• There are several types of relationships (one-to-one, one-to-many, many-to-many).
You can choose the appropriate one based on your design.

Setting the Relationship:

• Once you drag and drop a relationship line between two entities, a dialog will pop up.
• You can set cardinality (e.g., one-to-many, many-to-one) in this dialog box by
adjusting the min and max values for the relationship.
• Set foreign keys properly in this relationship dialog by linking a column in one table
to a corresponding column in another table.

Set Foreign Keys and Constraints

• As you define relationships, MySQL Workbench will help you set up foreign keys
automatically based on your relationships.
• For example, if you have a Dept ID in both the Faculty and Student tables, you
should link these two columns as a foreign key.
• Relationship Setup: You can also manually set foreign key relationships by going to
the table’s properties and selecting Foreign Keys to link columns between tables.

Customize Your Diagram (Optional)

• MySQL Workbench provides several options to format and organize the layout of
your diagram:
o Auto Arrange: You can automatically arrange the tables by right-clicking in
the diagram space and selecting Auto Layout.
o Manually Adjust Tables: You can drag and arrange tables for better
visualization and clarity.
o Resize tables and relationships to make sure everything fits neatly on the
screen.

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

OUTPUT

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

EXPERIMENT NO. 3

Objective : Writing SQL statements Using MYSQL.

a). Writing basic SQL SELECT statements.


SELECT:
• Retrieves specific data from one or more tables in a database.
• Syntax:
SELECT column1, column2 FROM table_name;

b). Restricting and sorting data.


WHERE Clause:
• Filters records based on specific conditions.
• Syntax:
SELECT column1 FROM table_name WHERE condition;

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

ORDER BY:
• Sorts the result set in ascending or descending order.
• Syntax:
SELECT column1 FROM table_name ORDER BY column1 ASC|DESC;

c). Displaying data from multiple tables.


Primary Key:
• A unique identifier for a record in a table; ensures data integrity.
• Syntax (while creating a table):
CREATE TABLE table_name (
column1 datatype PRIMARY KEY
);
Foreign Key:
• A field in a table that links to a primary key in another table.
• Syntax:
CREATE TABLE table_name (
column1 datatype,
FOREIGN KEY (column1) REFERENCES other_table(column_name)
);

TABLE-1

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

TABLE-2

INNER JOIN:
• Combines rows from two or more tables based on a related column.
• Syntax:
SELECT columns FROM table1 INNER JOIN table2 ON table1.column = table2.column;

Use of INNER JOIN

Syntax:
SELECT columns FROM table1 INNER JOIN table2 ON table1.column = table2.column
WHERE condition;

Use of INNER JOIN with WHERE clause

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

Syntax:
SELECT columns FROM table1 INNER JOIN table2 ON table1.column = table2.column
ORDER BY column_name ASC|DESC;

Use of INNER JOIN with ORDER BY clause

Syntax:
SELECT column1, aggregate_function(column2)
FROM table1
INNER JOIN table2
ON table1.column = table2.column
GROUP BY column1;
Use of INNER JOIN with GROUP BY clause

d). Aggregating data using group function


(i) MAX() - returns the maximum value of selected attributes
Synatx: SELECT MAX(column_name) FROM table_name;

(ii) MIN() - returns the minimum value of selected attributes


Syntax: SELECT MIN(column_name) FROM table_name;

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

(iii) AVG() – returns the average value of selected attributes


Synatx: SELECT AVG(column_name) FROM table_name;

(iv) COUNT() – returns the count of selected attributes


Syntax: SELECT COUNT(column_name) FROM table_name;

e). Manipulating data


ALTER:
• Modifies the structure of an existing table.
• Syntax:
ALTER TABLE table_name ADD column_name datatype;

UPDATE:
• Updates existing records in a table.
• Syntax:
UPDATE table_name SET column_name = value WHERE condition;

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

f). Creating and managing tables.


CREATE:
• Creates a new table or database.
• Syntax:
CREATE TABLE table_name (column1 datatype, column2 datatype);

DESCRIBE:
• Displays the structure of a table.
• Syntax:
DESCRIBE table_name;

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

INSERT INTO:
• Inserts new records into a table.
• Syntax:

INSERT INTO table_name (column1, column2) VALUES (value1, value2);

DROP:
• Deletes a table or database completely.
• Syntax:
DROP TABLE table_name;

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

EXPERIMENT NO. 4

OBJECTIVE: Subqueries/Nested queries and constraints and view

STEPS:

-- Step 1: Create Database


CREATE DATABASE student_db;
USE student_db;

-- Step 2: Create Table


CREATE TABLE students (
student_id INT PRIMARY KEY,
student_name VARCHAR(100),
course_id INT,
marks INT
);

-- Step 3: Insert Data


INSERT INTO students (student_id, student_name, course_id, marks) VALUES
(1, 'John Doe', 101, 75),
(2, 'Jane Smith', 102, 85),
(3, 'Alex Brown', 101, 65);

-- Step 4: Subquery to find students with marks above average


SELECT student_name
FROM students
WHERE marks > (SELECT AVG(marks)
FROM students
WHERE course_id = students.course_id);

OUTPUT:

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

-- Step 5: Add a constraint


ALTER TABLE students ADD CONSTRAINT chk_marks CHECK (marks BETWEEN 0
AND 100);

-- Step 6: Create a view


CREATE VIEW high_scores AS
SELECT student_name, marks
FROM students
WHERE marks > 70;

OUTPUT:

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

EXPERIMENT NO. 5

OBJECTIVE: Creating cursor

STEPS:

-- Step 1: Create Procedure with Cursor


DELIMITER $$
CREATE PROCEDURE fetch_high_marks_students()
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE student_name VARCHAR(100);
DECLARE student_cursor CURSOR FOR
SELECT student_name FROM students WHERE marks > 70;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;

OPEN student_cursor;
read_loop: LOOP
FETCH student_cursor INTO student_name;
IF done THEN
LEAVE read_loop;
END IF;
SELECT student_name;
END LOOP;
CLOSE student_cursor;
END $$
DELIMITER ;

-- Step 2: Call Procedure


CALL fetch_high_marks_students();

OUTPUT:

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

EXPERIMENT NO. 6

OBJECTIVE: Creating procedure and functions

STEPS:

-- Step 1: Create Function


DELIMITER $$
CREATE FUNCTION average_marks(course INT)
RETURNS DECIMAL(5,2)
BEGIN
DECLARE avg_marks DECIMAL(5,2);
SELECT AVG(marks) INTO avg_marks FROM students WHERE course_id = course;
RETURN avg_marks;
END $$
DELIMITER ;

-- Step 2: Create Procedure


DELIMITER $$
CREATE PROCEDURE insert_student(
IN stu_id INT,
IN stu_name VARCHAR(100),
IN course INT,
IN stu_marks INT
)
BEGIN
INSERT INTO students (student_id, student_name, course_id, marks)
VALUES (stu_id, stu_name, course, stu_marks);
END $$
DELIMITER ;

-- Step 3: Call Function and Procedure


SELECT average_marks(101);

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

CALL insert_student(4, 'Sam Wilson', 103, 90);


SELECT * FROM students;

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

EXPERIMENT NO. 7

OBJECTIVE: Creating packages and triggers

STEPS:

-- Step 1: Create Trigger


DELIMITER $$
CREATE TRIGGER check_marks_before_insert
BEFORE INSERT ON students
FOR EACH ROW
BEGIN
IF NEW.marks < 0 OR NEW.marks > 100 THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Marks should be between 0 and 100';
END IF;
END $$
DELIMITER ;

-- Step 2: Test Trigger


INSERT INTO students (student_id, student_name, course_id, marks)
VALUES (5, 'Error Test', 104, 150); -- This will raise an error

OUTPUT:

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

EXPERIMENT NO. 8

OBJECTIVE: Normalization

STEPS:

-- Step 1: Create Database


CREATE DATABASE IF NOT EXISTS normalization_db;
USE normalization_db;

-- Step 2: Create Unnormalized Table


CREATE TABLE students_courses_unnormalized (
student_id INT,
student_name VARCHAR(100),
course_id INT,
course_name VARCHAR(100),
marks INT
);

-- Insert Data into Unnormalized Table


INSERT INTO students_courses_unnormalized VALUES
(1, 'John Doe', 101, 'Math', 80),
(1, 'John Doe', 102, 'English', 85),
(2, 'Jane Smith', 101, 'Math', 90);

-- Step 3: Normalize to 1NF


CREATE TABLE students_courses_1nf (
student_id INT,
student_name VARCHAR(100),
course_id INT,
course_name VARCHAR(100),
marks INT
);
INSERT INTO students_courses_1nf
SELECT * FROM students_courses_unnormalized;

-- Step 4: Normalize to 2NF


CREATE TABLE students (
student_id INT PRIMARY KEY,
student_name VARCHAR(100)
);
CREATE TABLE courses (
course_id INT PRIMARY KEY,

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

course_name VARCHAR(100)
);
CREATE TABLE student_courses (
student_id INT,
course_id INT,
marks INT,
FOREIGN KEY (student_id) REFERENCES students(student_id),
FOREIGN KEY (course_id) REFERENCES courses(course_id)
);

-- Insert Data into Normalized Tables


INSERT INTO students VALUES (1, 'John Doe'), (2, 'Jane Smith');
INSERT INTO courses VALUES (101, 'Math'), (102, 'English');
INSERT INTO student_courses VALUES (1, 101, 80), (1, 102, 85), (2, 101, 90);

OUTPUT:

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

EXPERIMENT NO. 9

OBJECTIVE: Design and implementation of Library Information System

STEPS:

-- Step 1: Create Database


CREATE DATABASE IF NOT EXISTS library_db;
USE library_db;

-- Step 2: Create Tables


CREATE TABLE books (
book_id INT PRIMARY KEY,
title VARCHAR(255),
author VARCHAR(255),
publication_year INT
);

CREATE TABLE members (


member_id INT PRIMARY KEY,
member_name VARCHAR(100),
membership_date DATE
);

CREATE TABLE transactions (


transaction_id INT PRIMARY KEY,
book_id INT,
member_id INT,
issue_date DATE,
return_date DATE,
FOREIGN KEY (book_id) REFERENCES books(book_id),
FOREIGN KEY (member_id) REFERENCES members(member_id)
);

-- Step 3: Insert Sample Data


INSERT INTO books VALUES
(1, 'The Catcher in the Rye', 'J.D. Salinger', 1951),
(2, 'To Kill a Mockingbird', 'Harper Lee', 1960);

INSERT INTO members VALUES


(1, 'Alice', '2024-01-01'),
(2, 'Bob', '2024-01-15');

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

INSERT INTO transactions VALUES


(1, 1, 1, '2024-12-01', NULL);

-- Step 4: Create View for Available Books


CREATE OR REPLACE VIEW available_books AS
SELECT title, author
FROM books
WHERE book_id NOT IN (SELECT book_id FROM transactions WHERE return_date IS
NULL);

-- Step 5: Fetch View Data


SELECT * FROM available_books;

OUTPUT:

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

EXPERIMENT NO. 10

OBJECTIVE: Design and implementation of Student Information System

STEPS:

-- Step 1: Create Database


CREATE DATABASE IF NOT EXISTS student_info_db;
USE student_info_db;

-- Step 2: Create Tables


CREATE TABLE students (
student_id INT PRIMARY KEY,
student_name VARCHAR(100),
dob DATE
);

CREATE TABLE courses (


course_id INT PRIMARY KEY,
course_name VARCHAR(100)
);

CREATE TABLE enrollments (


student_id INT,
course_id INT,
enrollment_date DATE,
FOREIGN KEY (student_id) REFERENCES students(student_id),
FOREIGN KEY (course_id) REFERENCES courses(course_id)
);

-- Step 3: Insert Sample Data


INSERT INTO students VALUES
(1, 'John Doe', '2001-02-15'),
(2, 'Jane Smith', '2002-03-22');

INSERT INTO courses VALUES


(101, 'Mathematics'),
(102, 'Physics');

INSERT INTO enrollments VALUES


(1, 101, '2024-09-01'),
(2, 102, '2024-09-02');

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

-- Step 4: Fetch Data


SELECT s.student_name, c.course_name, e.enrollment_date
FROM students s
JOIN enrollments e ON s.student_id = e.student_id
JOIN courses c ON e.course_id = c.course_id;

OUTPUT:

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

EXPERIMENT NO. 11

OBJECTIVE: Automatic Backup of Files and Recovery of Files

STEPS:

1. Backup the database using the mysqldump command.


mysqldump -u root -p student_db > backup_student_db.sql

2. Restore the database using the mysql command.


mysql -u root -p student_db < backup_student_db.sql

OUTPUT:

Sample Content of backup_student_db.sql :


-- MySQL dump 10.13 Distrib 8.0.32, for Win64 (x86_64)
--
-- Host: localhost Database: student_db
-- ------------------------------------------------------
-- Server version 8.0.32
#Backup Command
CREATE DATABASE IF NOT EXISTS `student_db` /*!40100 DEFAULT CHARACTER
SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */;
USE `student_db`;
CREATE TABLE `students` (
`student_id` int NOT NULL,
`student_name` varchar(100) DEFAULT NULL,
PRIMARY KEY (`student_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO `students` VALUES (1,'John Doe'),(2,'Jane Smith');
#Recovery Command
SELECT * FROM students;

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

EXPERIMENT NO. 12

OBJECTIVE: Mini project (Design & Development of Data and Application)


Hotel Management System

STEPS:
1) Define the Requirements:
1.1) Manage guest details.
1.2) Track room availability and bookings.
1.3) Process payments.
1.4) Manage staff details.
2) Design the Database:
2.1) Identify entities: Guests, Rooms, Bookings, Payments, Staff.
2.2) Establish relationships:
2.2.1) Each guest can book one or more rooms.
2.2.2) Each booking generates a payment.
2.2.3) Staff members manage rooms and guests.
3) Create the Database Schema:
3.1) Design tables for each entity.
3.2) Add foreign keys to establish relationships.
4) Populate Sample Data:
4.1) Insert dummy data for testing.
5) Test Queries:
5.1) Write queries to handle operations such as new bookings, checking room
availability, and generating bills.

IMPLEMENTATION:

-- Step 1: Create Database


CREATE DATABASE hotel_management;

-- Use the database


USE hotel_management;

-- Step 2: Create Tables


-- Guests Table
CREATE TABLE guests (
guest_id INT AUTO_INCREMENT PRIMARY KEY,
guest_name VARCHAR(100) NOT NULL,
contact_number VARCHAR(15),
email VARCHAR(100),
address TEXT

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

);

-- Rooms Table
CREATE TABLE rooms (
room_id INT AUTO_INCREMENT PRIMARY KEY,
room_type VARCHAR(50), -- e.g., Single, Double, Suite
price_per_night DECIMAL(10, 2),
is_available BOOLEAN DEFAULT TRUE
);

-- Bookings Table
CREATE TABLE bookings (
booking_id INT AUTO_INCREMENT PRIMARY KEY,
guest_id INT,
room_id INT,
check_in_date DATE,
check_out_date DATE,
FOREIGN KEY (guest_id) REFERENCES guests(guest_id),
FOREIGN KEY (room_id) REFERENCES rooms(room_id)
);

-- Payments Table
CREATE TABLE payments (
payment_id INT AUTO_INCREMENT PRIMARY KEY,
booking_id INT,
payment_date DATE,
amount DECIMAL(10, 2),
payment_method VARCHAR(50), -- e.g., Cash, Credit Card
FOREIGN KEY (booking_id) REFERENCES bookings(booking_id)
);

-- Staff Table
CREATE TABLE staff (
staff_id INT AUTO_INCREMENT PRIMARY KEY,
staff_name VARCHAR(100),
role VARCHAR(50), -- e.g., Manager, Receptionist, Housekeeping
contact_number VARCHAR(15)
);

-- Step 3: Insert Sample Data


-- Insert into Guests
INSERT INTO guests (guest_name, contact_number, email, address) VALUES
('John Doe', '1234567890', '[email protected]', '123 Elm Street'),
('Jane Smith', '9876543210', '[email protected]', '456 Oak Avenue');

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

-- Insert into Rooms


INSERT INTO rooms (room_type, price_per_night, is_available) VALUES
('Single', 100.00, TRUE),
('Double', 150.00, TRUE),
('Suite', 300.00, TRUE);

-- Insert into Staff


INSERT INTO staff (staff_name, role, contact_number) VALUES
('Alice Brown', 'Manager', '1112223333'),
('Bob Green', 'Receptionist', '4445556666');

-- Insert into Bookings


INSERT INTO bookings (guest_id, room_id, check_in_date, check_out_date) VALUES
(1, 2, '2024-12-01', '2024-12-05'),
(2, 3, '2024-12-03', '2024-12-07');

-- Insert into Payments


INSERT INTO payments (booking_id, payment_date, amount, payment_method) VALUES
(1, '2024-12-01', 600.00, 'Credit Card'),
(2, '2024-12-03', 1200.00, 'Cash');

-- Step 4: Test Queries


-- 1. Display all available rooms
SELECT * FROM rooms WHERE is_available = TRUE;

-- 2. Retrieve guest details for a specific booking


SELECT g.guest_name, g.contact_number, g.email
FROM guests g
JOIN bookings b ON g.guest_id = b.guest_id
WHERE b.booking_id = 1;

MADHURENDRA KUMAR 2201921530096


[Approved by AICTE, Govt. of India & Affiliated to Dr.APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)

-- 3. Calculate total payment for a booking


SELECT SUM(p.amount) AS total_payment
FROM payments p
WHERE p.booking_id = 1;

-- 4. List all bookings with guest and room details


SELECT b.booking_id, g.guest_name, r.room_type, b.check_in_date, b.check_out_date
FROM bookings b

JOIN guests g ON b.guest_id = g.guest_id


JOIN rooms r ON b.room_id = r.room_id;

-- 5. Display staff details by role


SELECT * FROM staff WHERE role = 'Manager';

MADHURENDRA KUMAR 2201921530096

You might also like