DBMS 7 Experiments
DBMS 7 Experiments
DBMS 7 Experiments
Step 1: Download the MySQL Installer from dev.mysql.com. The two download options are a web-
Community version and a full version. The web-community version will only download the server,
by
default , but you can select other applications (like Workbench) as desired. The full installer will
You’ll also be asked to create a user account, but you skip this part by scrolling down to the bottom
and clicking “No thanks, just start my download”.
Step 2: Run the installer that you downloaded from its
location on your system,
generally by double-clicking.
Tools: Draw.io
Objective: Creating Entity-Relationship Diagram using case tools.
Theory & Concept:
ER Diagram (Entity-Relationship Diagram)
The Entity Relationship Diagram explains the relationship among the entities present in the database.
The ER Diagram is the structural format of the database.
Symbols Used in ER Diagram
It is used to model the logical view of the system from a data perspective which consists of these
symbols:
Components of ER Diagram
ER Model consists of Entities, Attributes, and Relationships among Entities in a Database System.
1) Entity
i. Strong Entity
ii. Weak Entity
2) Attributes
i. Key
ii. Composite
iii. Multivalued
iv. Derived
3) Relationship
i. One to One
ii. One to Many
iii. Many to One
iv. Many to Many
• Song
• Artist
• Playlist
• User
• Subscription
• Genre
Relationships:
• Char (n)- A fixed length character length string with user specified length .
• Varchar (n)- A variable character length string with user specified maximum length n.
• Int- An integer.
• Small integer- A small integer.
• Numeric (p, d)-A Fixed point number with user defined precision.
• Real, double precision- Floating point and double precision floating point numbers with
machine dependent precision.
• Float (n)- A floating point number, with precision of at least n digits.
• Date- A calendar date containing a (four digit) year, month and day of the month. •
Time- The time of day, in hours, minutes and seconds Eg. Time ’09:30:00’. •
Number- Number is used to store numbers (fixed or floating point).
Practical 1
EMPLOYEE TABLE
EMP_NAME VARCHAR(30)
DESIGNATION CHAR(10)
DOJ DATE
SALARY NUMBER(9,2)
ADDR VARCHAR(30)
DEPT_NAME CHAR(30)
3. List the name of emp who belong to Mathura and depart name is MARKETING
4. List the name of emp who are getting their salary in between 800 and 2500
6. List the employees who are earning more than 1200 but less than 4000.
7. List the employees who have joined after 1st Jan 84 in the order of the joining date.
Theory Concept:
Normalization is a database design process used to organize data in a relational database
efficiently and reduce data redundancy. It is a multi-step process that sets the data into tabular form
and removes the duplicated data from the relational tables. Normalization typically involves
dividing a database into two or more tables and defining relationships between them. Let's go
through an example of normalizing a database with sample data and MySQL queries. We'll start
with an unnormalized table and normalize it step by step.
We'll normalize the data by creating two separate tables: "Customers" and "Orders." The
"Customers" table will store customer information, and the "Orders" table will store order
information.
Now that we have normalized our data, we can query the "Customers" and "Orders"
tables to retrieve information:
Output:
These queries demonstrate the result of normalizing the data. The "Customers" table
contains unique customer information, and the "Orders" table stores order details with a reference
to the customer. The last query retrieves the total order amount for each customer, demonstrating
the power of relational databases and normalization.
Experiment No-5
Program Name: Design and implementation of Student Information System.
Theory Concept:
Experiment Scenario:
You are tasked with creating a Student Information System (SIS) for a university. The
system should store information about students, courses, and grades. Students can enroll in courses,
and teachers can enter grades for students in those courses.
Experiment Steps:
1. Database Design:
Define the database schema with tables for students, courses, and grades.
Here's a simplified schema:
-- Students table
CREATE TABLE students (
student_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
birthdate DATE,
email VARCHAR(100)
);
-- Courses table
CREATE TABLE courses (
course_id INT PRIMARY KEY,
course_name VARCHAR(100),
teacher VARCHAR(100)
);
-- Grades table
CREATE TABLE grades (
grade_id INT PRIMARY KEY,
student_id INT,
course_id INT,
grade VARCHAR(2),
FOREIGN KEY (student_id) REFERENCES students(student_id),
FOREIGN KEY (course_id) REFERENCES courses(course_id)
);
2. Data Population:
4. CRUD Operations:
Practice performing CRUD (Create, Read, Update, Delete) operations on the database.
For example,
you can add a new student, update a student's information, or delete a course.
Program Name: Write a CURSOR to display list of clients in the client Master Table.
TheoryConcept:The following example would illustrate the concept of CURSORS. We will be using
the CLIENT_MASTER table and display records.
Implementation:
DECLARE
CURSOR client_cur
isSELECT
id,name,address
FROM client_master;
client_rec
client_cur%rowtype;B
EGIN
OPENclient_cur;
LOOP
FETCH client_cur into
client_rec;EXITWHENclient_
cur%notfound;
DBMS_OUTPUT.put_line(client_rec.id||''||client_rec.nam
e);END LOOP;
END;
/
Output:Whenthe above codeis executed atSQLprompt,itproduces thefollowing result:
1 Ramesh
2 Khilan
3 kaushik
4 Chaitali
5 Hardik
6 Komal
ProgramName: Execute queries related to Exists, Not Exists, Union, Intersection, Difference, Join
ontablesCLIENT_MASTER,PRODUCT_MASTER,SALESMAN_MASTER,SALES_ORDER,SALES_O
RDER_DETAILS
TheoryConcept:
Theprogramretrievesdatafromrecordsbydefiningrelationbetweentwotablessoastoretrievefilteredrecords.
Implementation:
CorrelatedquerieswithEXISTS/NOTEXISTSclause
2) Selectorder_no and order_date for all orders which include product_no ‘P001’ and
quantity_ordered>10Ans:Select order_no,order_data from sales_order where exists(select * from
sales_order_details wheresales_order_details,order_no = sales_order.Order_no and product-
no=’p001’ and quantity-ordered>10;Output:
Order_no Product_no
0002 05/feb/13
Order_no
0003
Output:
Order_no Order_date
0001 23/jan/13
Client_no Name
3 Akshita
4 Dhawal
2) List all the clients and their names who are also salesman.
Ans:Selectnamefromclient_masterINTERSECT,selectnamefromsalesman_master;
Output:
No rows selected
Name
Akshita
Dhawal
Akansha
Divya
Dorothy
Client_no
6
7
5) Listalltheclientswhohavenotplacedanyorder.
Client_no
3
4
5
Client_no
3
4
5
7) FindalltheclientsandtheirnamesfromcityGhaziabadwhohavedeliverydateoftheirordersastoday.Ans:
Select client_no from client_master where city=’Ghaziazbad’ INTERSECT select client_no
fromsales_order where delivery_date=’09-MAR-13’
Output:
Client_no
5
Queries on Joins
1) List the product_no and description of products sold.
Ans:Select product_no, description from (product1 natural join sales_order_details)
Output:
Product_no Description
1 Chair
1 Chair
2 Table
3 Sofa
Output:
Name
Akshita
Akansha
5)
6) List theorders forlessthan 5unitsof saleof‘chair’
Ans:Select product_no, order_no from (sales_order_details natural join product1)
where(description=’chair’and qty_ordered<5);
Output:
Product_no Order_no
1 0001
1 0001
8) Find the products and their quantities for the orders placed by the client_no ‘3’and ‘5’
Ans:Selectproduct_no,description,qty_orderedfrom(product1naturaljoinsales_order_detailsnaturaljoin
sales_order natural join client_master) where (client_no=3 OR client_no=5);
Output:
PRODUCT_NO DESCRIPTION QTY_ORDERED
1 Chair 4
1 Chair 3