You are on page 1of 22

UNIVERSITY SCHOOL OF

INFORMATION, COMMUNICATION
AND
TECHNOLOGY

Relational Database Management System Lab Work

Submitted By:
Name: Taruun R Malik
Roll no. : 04916401521
Class: B.Tech(IT-3rd Semester)

Batch: 2021-2025
S.No. Objective Date
Draw an ER Diagram along with necessary
1. DFDs for the assigned database i.e. Company
Insurance Database.

On tables perform queries: i) Creating


2. Records and ii) Viewing Records

On tables perform queries : i)


3. Inserting/Updating Records ii)Deleting
Records
On tables perform aggregate functions: i) Order By
4. Clause ii)Group By Clause

On tables perform queries: i) Saving(Commit)


5. ii)Undoing(Rollback) iii)JOINS on tables

6. On tables perform queries: i) Altering table


ii)Renaming table iii)Truncate and Date functions

On tables perform queries: i) Selection ii)Projection


7. iii)USE CHECK and DEFAULT on tables

On tables perform queries : i) Ordering ascending


8. and descending ii) Triggers

Show appropriate normalization of the tables


9.
PRACTICAL-1

Draw an ER Diagram along with necessary DFDs for the assigned database i.e. Company
Insurance Database.

An ER Diagram is a schematic representation of a database, it mainly contains entities, their


attributes and their relationships with other entities. ER diagrams represent entities with a
rectangle, attributes with an oval and relationships with a rhombus. The purpose of ER
diagrams is to represent the entity relationship framework.
Why should one use an ER diagram? Here’s why:
1. Helps you to define terms related to entity relationship modeling.
2. Provides a concise and clear overview of the entire database.
3. ER diagrams can be translated into relational data models easily.
PRACTICAL-2
On tables perform queries: i) Creating Records ii) Viewing Records

i) Creating database and required tables:


Creating databases and required tables can be done easily using CREATE command.

ii) Viewing tables:

As tables are currently empty, we shall view them using DESCRIBE command on mysql.
PRACTICAL-3
On tables perform queries : i) Inserting/Updating Records ii)Deleting Records

i)Insertions:

Values can be inserted in a table anytime, but the constraint is if a particular value is not set by default at the time of
creation and still left empty will result in an error.
ii) Deletions:

Entries/Tuples can be deleted any time using the DELETE command, but if no such tuple exists an error would be
thrown.

Here are the same tables as before after deleting one row from each.
PRACTICAL-4
On tables perform aggregate functions: i) Order By Clause ii)Group By Clause

i) Order by:

The ORDER BY keyword is used to sort the result-set in ascending or descending order.

ii)Group by:
The GROUP BY statement is often used with aggregate functions (COUNT(), MAX(), MIN(), SUM(), AVG()) to group the result-set by one or more
columns.
PRACTIAL-5
On tables perform queries: i) Saving(Commit) ii)Undoing(Rollback) iii)JOINS on tables

i) Saving(Commit) And ii) Undoing(Rollback) :


ii) Joins in a table:
a) Left join :
The LEFT JOIN keyword returns all records from the left table (table1), and the matching records (if any) from the right table
(table2).

b) Right join:
The RIGHT JOIN keyword returns all records from the right table (table2), and the matching records (if any) from the left table
(table1).
c) Inner join:

The INNER JOIN keyword selects records that have matching values in both tables.

d) Cross join:

The CROSS JOIN keyword returns all records from both tables (table1 and table2).
PRACTICAL-6

On tables perform queries: i) Altering table ii)Renaming table iii)Truncate and Date functions

i)ALTERING TABLE BY ADDING A COLUMN :

The ALTER TABLE statement is used to add, delete, or modify columns in an existing table.

ALTERING TABLE BY DROPPING THE SAME ADDED COLUMN :


ii) RENAMING TABLE :
Sometimes we may want to rename our table to give it a more relevant name. For this purpose we can use
ALTER TABLE to rename the name of table. Its syntax:
ALTER TABLE table_name
RENAME TO new_table_name;

iii) TRUNCATING A NEWLY CREATED TABLE:


Truncate table does not delete the table but it deletes the contents of the table.
DATE FUNCTIONS :

While working with database, the format of the date in table must be matched with the input date in order to insert.
In various scenarios instead of date, datetime (time is also involved with date) is used.

Sql has built in date functions such as: Now(),Curtime(),Curdate().


PRACTICAL-7
On tables perform queries: i) Selection ii)Projection iii)USE CHECK and DEFAULT on tables

i) Selection and ii) Projection


Selection is used to select the entire table while projection is used to select some of the columns of the
table. Select retrieves the tuples (rows) in a relation (table) for which the condition in 'predicate' section
(WHERE clause) stands true. Project retrieves the attributes (columns) specified.
iii) DEFAULT AND CHECK:

Check caught age=16, while rest were successfully executed:


PRACTICAL-8:

On tables perform queries : i) Ordering ascending and descending ii) Triggers

i) Ordering Ascending and Descending:


Sql offers to format the data within tables in ascending or descending order.
Can be easily done by command: ORDER BY attribute desc/asc;

Working with triggers:


Explanation:

Here, when a new tuple is inserted our ‘setInsurance’ trigger is called which sets the value of ‘insurance_status’ to
‘claimed’.
PRACTICAL-9
NORMALIZATION OF TABLES:
1NF-FIRST NORMAL FORM:

---A table is in 1 NF if: 

1. There are only Single Valued Attributes.

2. Attribute Domain does not change.

3. There is a unique name for every Attribute/Column.

4. The order in which data is stored does not matter. 

Tables created for the objective of an ‘Insurance Company’ Database are all 1NF normalized as none of the tuples
have redundancy and atomicity is carefully preserved.

Car table:
Accident Table:

Person Info Table:


2NF-SECOND NORMAL FORM:

---To be in second normal form:

1. A relation must be in first normal form


2. Relation must not contain any partial dependency.
3. A relation is in 2NF if it has No Partial Dependency, i.e., no non-prime attribute (attributes which are not
part of any candidate key) is dependent on any proper subset of any candidate key of the table.

To show the concept of 2NF, Car table was used. ‘Year’ attribute was able to partially describe ‘Damage Amount’
attribute i.e. ‘DamageAmt’ was partially dependent on ‘Year’ so, ‘Car’ table was divided into two sub-tables:
‘2NFCarLeft’ and ‘2NFCarRight’

2NFCarLeft Table:

2NFCarRight Table:
Thus, 2NF form of normalization was depicted using ‘Car’ Table. As none of the tuples in ‘Car’ table were repeated
and each cell had one value only, it was obvious that the table was already 1NF normalized.

3NF-THIRD NORMAL FORM:

--A relation is in 3NF if at least one of the following condition holds in every non-trivial function dependency X –> Y:

1. X is a super key.

2. Y is a prime attribute (each element of Y is part of some candidate key).

3. A relation is 2NF qualified normalized.

All of the tables were already 3NF normalized as none of the tables had transitive dependency and were all 2NF
normalized. Take ‘Accident’ table for example, here ‘reportID’ attribute can determine all the remaining
attributes. Example, date can be determined by reportID itself, location can be determined by reportID, even
damageAmt can be determined by reportID.

BCNF:

--A relation is in BCNF, if and only if, every determinant is a Form (BCNF) candidate key.

To show BCNF normal form, a new table was created and it was named ‘StudentAndProfessor’

One subject may be taught by multiple professors. This shows that there is a dependency between the subject & the
professor, and the subject is always dependent on the professor (professor -> subject).  This is not allowed in BCNF
in DBMS. For BCNF, the deriving attribute (professor here) must be a prime attribute.

To satisfy BCNF, we would divide this table in two different tables where professorID would be a primary key.

You might also like