0% found this document useful (0 votes)
4 views

Lab Manual For DBMS

fffewsfs

Uploaded by

australiat47
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Lab Manual For DBMS

fffewsfs

Uploaded by

australiat47
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Lab :1

E2UC302B : Data Base management System


B.Tech CSE (AIML) _ 2023-24 _Sem III
Date:29 August 2024
Objective :
Draw an E-R diagram and convert entities and relationships to a relation table for a given scenario.
(Two assignments shall be carried out i.e. consider two different scenarios (e.g. Bank *, University )

Example:

Required Knowledge:

 ERD
 Tables: Faculty, Student, Course, Subjects, Exams, Department, Hostel (Draw Tables and identification of
primary key : Students)

Student`s Task:
Draw ERD and design Tables for
1. Bank Management System 9. Vehicle Parking Management System
2. Galgotias University Management System 10. Restaurant Management System
3. School Management System 11. Pharmacy Management System
4. Hostel Management System 12. Railway Management System
5. Hotel Management System 13. ATM Management System
6. Society Management System 14. Event Management System
7. Library Management System 15. Car Showroom Management System
8. Hospital Management System 16. Pharmacy Management System
Lab :2
E2UC302B : Data Base management System
B.Tech CSE (AIML) _ 2023-24 _Sem III
Date:
Objective:

Implementation of DDL commands of SQL with suitable examples.


Create a table named Books with the following columns:
Book ID (Primary Key, Integer)
Title (Variable Character, 200 characters)
Author (Variable Character, 100 characters)
Published Date (Date)
ISBN (Variable Character, 13 characters)
a) Alter the Books table to add a column named Genre (Variable Character, 50 characters).
b) Modify the ISBN column to increase its length to 20 characters.
c) Drop the Published Date column from the Books table.
d) Drop the Books table from the database.

Below are the SQL statements for each of the tasks:

1. Create the Books table

CREATE TABLE Books


( BookID INT PRIMARY KEY,
Title VARCHAR(200),
Author VARCHAR(100),
PublishedDate DATE,
ISBN VARCHAR(13)
);

2. Alter the Books table to add a column named Genre

ALTER TABLE Books


ADD Genre VARCHAR(50);
3. Modify the ISBN column to increase its length to 20 characters

ALTER TABLE Books


MODIFY ISBN VARCHAR(20);
4. Drop the PublishedDate column from the Books table

ALTER TABLE Books


DROP COLUMN PublishedDate;
5. Drop the Books table from the database

DROP TABLE Books;


Explanation:

1. Create Table: The CREATE TABLE statement defines a new table named Books with columns for BookID, Title,
Author, PublishedDate, and ISBN. The BookID column is defined as the primary key.

2. Alter Table to Add Column: The ALTER TABLE statement with ADD adds a new column Genre to the Books
table.

3. Modify Column: The ALTER TABLE statement with MODIFY changes the ISBN column to have a length of 20
characters instead of 13.

4. Drop Column: The ALTER TABLE statement with DROP COLUMN removes the PublishedDate column from
the Books table.

5. Drop Table: The DROP TABLE statement completely removes the Books table from the database.
Lab :3
E2UC302B : Data Base management System
B.Tech CSE (AIML) _ 2023-24 _Sem III
Date:
Objective:

Implementation of DML commands of SQL with suitable examples.


You are managing a database for a bookstore. Implement the following tasks:
a) Insert the following data into a table named Books with columns
BookID,
Title,
Author,
PublishedDate,
ISBN, and Price.
Data:
(1, 'The Great Gatsby', 'F. Scott Fitzgerald', '1925-04-10', '9780743273565', 10.99)
(2, '1984', 'George Orwell', '1949-06-08', '9780451524935', 9.99)

b) Update the Books table to change the Price of the book with Book ID 1 to 12.99.
c) Delete the book with Book ID 2 from the Books table.

Below are the SQL statements to perform the tasks :

CREATE TABLE Books


(
BookID INT PRIMARY KEY,
Title VARCHAR(200),
Author VARCHAR(100),
PublishedDate DATE,
ISBN VARCHAR(13) ,
Price DECIMAL(10, 2)
);
a. Insert data into the Books table
INSERT INTO Books (BookID, Title, Author, PublishedDate, ISBN, Price)
VALUES
(1, 'The Great Gatsby', 'F. Scott Fitzgerald', '1925-04-10', '9780743273565', 10.99),
(2, '1984', 'George Orwell', '1949-06-08', '9780451524935', 9.99);

b. Update the Books table to change the Price of the book with BookID = 1 to 12.99
UPDATE Books
SET Price = 12.99
WHERE BookID = 1;
c. Delete the book with BookID = 2 from the Books table
DELETE FROM Books
WHERE BookID = 2;
Explanation:
1. Insert Data:
o The INSERT INTO statement is used to add two rows of data into the Books table.
o Each row corresponds to a book with details such as BookID, Title, Author,
PublishedDate, ISBN, and Price.
2. Update Data:
o The UPDATE statement modifies the Price of the book where BookID equals 1.
o The price is updated from 10.99 to 12.99.
3. Delete Data:
o The DELETE statement removes the book with BookID = 2 from the Books table.
Lab :3
E2UC302B : Data Base management System
B.Tech CSE (AIML) _ 2023-24 _Sem III
Date:
Objective:

Implementation of different types of operators in SQL.


You have two tables Products and Sales.
Implement the following tasks using various operators:
1. Find all products with a price greater than 100.
2. List all sales that happened in the year 2023.
3. Find all products whose name contains the word 'Pro'.
4. Combine the lists of products and sales to find all unique product names and sale items.
5. Find the total revenue generated from sales, assuming each sale has a quantity and price.

To implement the tasks assume the structure of the Products and Sales tables as follows:
Table Structure Assumptions:
 Products Table:
o ProductID (Primary Key)
o ProductName (VARCHAR)
o Price (DECIMAL)
 Sales Table:
o SaleID (Primary Key)
o ProductID (Foreign Key)
o SaleDate (DATE)
o Quantity (INT)
o Price (DECIMAL) — This can be the price at the time of sale.

Table Assumed:
1. Products Table
CREATE TABLE Products
(
ProductID INT PRIMARY KEY,
ProductName VARCHAR(100),
Price DECIMAL(10, 2)
);
2. Sales Table
CREATE TABLE Sales
(
SaleID INT PRIMARY KEY,
ProductID INT,
SaleDate DATE,
Quantity INT,
SalePrice DECIMAL(10, 2),
FOREIGN KEY (ProductID) REFERENCES Products(ProductID)
);

SQL Queries for the Tasks


1. Find all products with a price greater than 100
SELECT * FROM Products
WHERE Price > 100;
2. List all sales that happened in the year 2023
SELECT * FROM Sales
WHERE YEAR(SaleDate) = 2023;
3. Find all products whose name contains the word 'Pro'
SELECT * FROM Products
WHERE ProductName LIKE '%Pro%';
4. Combine the lists of products and sales to find all unique product names and sale items
SELECT DISTINCT ProductName FROM Products
UNION
SELECT DISTINCT SalePrice FROM Sales;

(Note: The above query assumes you want to find unique product names and sale prices as distinct items, but if you
meant something else, the query might need adjustments.)
5. Find the total revenue generated from sales
SELECT SUM(Quantity * SalePrice) AS TotalRevenue
FROM Sales;

Explanation:
1. Products with Price > 100:
o The SELECT query filters products based on the Price column, returning only those with a price
greater than 100.
2. Sales in 2023:
o The YEAR() function extracts the year part from the SaleDate and filters for records in 2023.
3. Products Containing 'Pro':
o The LIKE operator is used to search for the substring 'Pro' within the ProductName column.
4. Combine Product Names and Sale Items:
o The UNION operator combines the results from the Products and Sales tables and returns
unique values from both sets.
5. Total Revenue:
o The SUM() function calculates the total revenue by multiplying Quantity by SalePrice for each
sale record and summing them up.
1 Draw an E-R diagram and convert entities and relationships to a relation table for a given scenario.

(Two assignments shall be carried out i.e. consider two different scenarios (e.g. bank, college)

2 Implementation of DDL commands of SQL with suitable examples.

3 Implementation of DML commands of SQL with suitable examples.

4 Implementation of different types of operators in SQL.

5 Implementation of different types of operators in SQL.

6 Perform the following: a. Creating Tables (With and Without Constraints(Key/Domain), b. Creating Tables

(With Referential Integrity Constraints)

7 For a given set of relation schemes, create tables and perform the following Queries:

a. Simple Queries

b. Queries with Aggregate functions (Max/Min/Sum/Avg/Count),

c. Queries with Aggregate functions (group by and having clause),

d. Queries involving- Date Functions, String Functions, Math Functions

8 For a given set of relation schemes, create tables and perform the following Queries: Inner Join,

a. Outer Join Subqueries- With IN clause, With EXISTS clause

9 For a given set of related tables perform the following:-

a. Creating Views ,

b. Dropping views,

c. Selecting from a view

10 Implementation of Group by & Having Clause, Order by Clause, Indexing.

11 Given the table EMPLOYEE (EmpNo, Name, Salary, Designation, DeptID) write a cursor to select the

five highest-paid employees from the table.

12 For a given set of related tables perform the following: a. Begin Transactions b. End Transaction

13For a given set of related tables perform the following: a. Create roles b. Assign Privileges c. Revoke Privileges
14 Write a Pl/SQL program using a FOR loop to insert ten rows into a database table.

15 Perform the following: Inserting/Updating/Deleting Records in a Table, Saving (Commit) and Undoing (rollback)

Installing MySQL Server for use with MySQL Workbench


Steps:
1. Download MySQL Installer
1. Go to the MySQL Website:
o Visit the MySQL Downloads page.
2. Download MySQL Installer:
o For Windows: Download the MySQL Installer for Windows (choose the appropriate
version, usually the "MySQL Installer Community" version).
2. Install MySQL Server on Windows
1. Run the MySQL Installer:
o After downloading, run the installer. You may need administrative privileges.
2. Choose Setup Type:
o You can select Developer Default (which installs MySQL Server, Workbench, and other
tools) or Custom (to choose specific components).
3. Select Products and Features:
o Ensure that MySQL Server is selected, along with MySQL Workbench if it’s not already
installed.
4. Installation Path:
o You can leave the default installation path or change it if needed.
5. Apply Configuration:
o The installer will then install the selected products. Click Execute to start the
installation.
6. Configure MySQL Server:
o Choose a configuration type:
 Standalone MySQL Server: If running locally.
o MySQL Server Configuration:
 Choose a root password and set up a user if needed.
 Default Port: 3306 (you can change it if necessary).
o Choose whether to run MySQL as a Windows service (recommended).
7. Start MySQL Server:
o After installation, ensure MySQL Server starts. You can start it from the Windows
Services panel if it doesn't start automatically.
8. Complete Installation:
o Once configuration is complete, click Finish. MySQL Server should now be running.

You might also like