DBMS LAB final
DBMS LAB final
APJ
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of CSE(AIML)
LAB MANUAL
ACADEMIC SESSION 2024-25(ODD SEM)
NAME: MADHURENDRA KUMAR
ROLL NO: 2201921530096
COURSE: B. TECH (CSEAIML)
SEM: V
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.
EXPERIMENT NO. 1
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
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:
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:
Since we chose the Custom setup type, the MySQL Installer displays available products for us
to select to install.
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.
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.
After the download is complete, click the Execute button to start the installation.
The MySQL Installer will install the selected products and this process may some time.
After the installation is complete, click the Next button to proceed to the Product
Configuration.
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.
It’s recommended to use strong password encryption for authentication, which is the first
option.
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.
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.
In this step, you grant permission to MySQL to access the data directory.
The MySQL Installer displays a window with the configuration steps. Click the Execute button
to apply the 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.
The MySQL Installer displays a window to notify you that the installation is complete. Click
the Finish button to close the installer.
EXPERIMENT NO. 2
Theory :
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.
Steps :
• Launch MySQL Workbench. Ensure that you have a running MySQL instance (it can
be a local or remote server).
• File -> New Model: This opens up a new workspace where you will be able to create
your ER diagram.
• A blank diagram will open in a new tab within MySQL Workbench where you can
add your tables and relationships.
• 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).
• 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.
• 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.
• 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.
• 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.
OUTPUT
EXPERIMENT NO. 3
ORDER BY:
• Sorts the result set in ascending or descending order.
• Syntax:
SELECT column1 FROM table_name ORDER BY column1 ASC|DESC;
TABLE-1
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;
Syntax:
SELECT columns FROM table1 INNER JOIN table2 ON table1.column = table2.column
WHERE condition;
Syntax:
SELECT columns FROM table1 INNER JOIN table2 ON table1.column = table2.column
ORDER BY column_name ASC|DESC;
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
UPDATE:
• Updates existing records in a table.
• Syntax:
UPDATE table_name SET column_name = value WHERE condition;
DESCRIBE:
• Displays the structure of a table.
• Syntax:
DESCRIBE table_name;
INSERT INTO:
• Inserts new records into a table.
• Syntax:
DROP:
• Deletes a table or database completely.
• Syntax:
DROP TABLE table_name;
EXPERIMENT NO. 4
STEPS:
OUTPUT:
OUTPUT:
EXPERIMENT NO. 5
STEPS:
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 ;
OUTPUT:
EXPERIMENT NO. 6
STEPS:
EXPERIMENT NO. 7
STEPS:
OUTPUT:
EXPERIMENT NO. 8
OBJECTIVE: Normalization
STEPS:
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)
);
OUTPUT:
EXPERIMENT NO. 9
STEPS:
OUTPUT:
EXPERIMENT NO. 10
STEPS:
OUTPUT:
EXPERIMENT NO. 11
STEPS:
OUTPUT:
EXPERIMENT NO. 12
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:
);
-- 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)
);