Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Database Management Systems (It 311) : Department of Information and Technology

Download as pdf or txt
Download as pdf or txt
You are on page 1of 60

DATABASE MANAGEMENT SYSTEMS (IT 311)

Department of Information and Technology

SHAHID AFRIDI SAIKIA


Name: ……………………………………………………………………………….…………
th
190103007
ROLL No: ….…………………………………….…Semester: 5 Semester
………………………...…
CSE
Branch:…………………………………………………………………………………………
Foreword 1

SQL COMMANDS

Structured Query Language(SQL) Commands: SQL commands are


instructions. It is used to communicate with the database. It is also used
to perform specific tasks, functions, and queries of data.SQL can perform
various tasks like create a table, add data to tables, drop the table,
modify the table, set permission for users.
The SQL commands are mainly categorized into four categories as:
1. DDL – Data Definition Language
2. DQl – Data Query Language
3. DML – Data Manipulation Language
4. DCL – Data Control Language
According to other resources,there exists another category of SQL
clauses that is
5.TCL – Transaction Control Language.
SQL COMMANS
DDL DML TCL DQL DCL

1.CREATE 1.INSERT 1.COMMIT 1.SELECT 1.GRANT

2.Drop 2.UPDATE 2.SAVEPOINT 2.REVOKE

3.ALTER 3.DELETE 3.ROLLBACK

4.TRUNCATE 4.CALL 4.SET


Transaction
5.EXPLAIN 5.SET
CALL
constraint

6.LOCK

a) DDL (Data Definition Language):

DDL also known as Data Definition Language defines commands for defining
relation schemas, deleting relations, creating indexes and modifying relation
schemas.

List of DDL commands:


1. CREATE: This command is used to create the database or its objects
(like table, index, function, views, store procedure, and triggers).
Syntax: CREATE TABLE TABLE_NAME (COLUMN_NAME DATA TYPES[,. ]);
2. DROP: This command is used to delete objects from the

database. Syntax: DROP TABLE table_name;


3. ALTER: This is used to alter the structure of the

database. Syntax: i)To add a new column in the table


ALTER TABLE table_name ADD column_name COLUMN-
definition; ii)To modify existing column in the table:
ALTER TABLE table_name MODIFY(column_definitions. );

4. TRUNCATE: This is used to remove all records from a table,


including all spaces allocated for the records are removed.
Syntax: TRUNCATE TABLE table_name;
5. COMMENT: This is used to add comments to the data
dictionary. 6.RENAME: This is used to rename an object
existing in the database

b) DQL (Data Query Language):

DQL statements are used for performing queries on the data within schema
objects.The purpose of the DQL Command is to get some schema relation
based on the query passed to it. We can define DQL as follows: it is a
component of SQL that allows getting data from the database and
imposing order upon it. SELECT - The SQL SELECT statement is used to
fetch the data from a database table which returns this data in the form of
a result table. These result tables are called result-sets.
Syntax:

SELECT
expressions
FROM TABLES
WHERE condition

c) DML(Data Manipulation Language):


DML also known as Data Manipulation Language includes commands
to insert, delete and modify tuples in the database, and it is used to
store, modify, retrieve, delete and update data in a database.
List of DML commands:
1) INSERT : It is used to insert data into a table.
Syntax: i) INSERT INTO TABLE_NAME
(col1, col2, col3, col N)
VALUES (value1, value2, value3, valueN);
Or
ii) INSERT INTO TABLE_NAME
VALUES (value1, value2, value3, valueN);

2) UPDATE: It is used to update existing data within a


table. Syntax: UPDATE table_name SET
[column_name1= value1, column_nameN =
valueN] [WHERE CONDITION]

3) DELETE : It is used to delete records from a database


table. Syntax: DELETE FROM table_name [WHERE
condition];

4) LOCK: Table control concurrency.


5) CALL: Call a PL/SQL or JAVA subprogram.
6) EXPLAIN PLAN: It describes the access path to data.

d) DCL (Data Control Language):

DCL is the short name of Data Control Language which includes


commands such as GRANT and is mostly concerned with rights,
permissions and other controls of the database system.

List of DCL commands:

1. GRANT - The GRANT command in SQL gives access or privileges to the


users of the database. Three major components which are involved in
authorization are users, privilege/s(operation), and a database object.
Syntax : GRANT SELECT, UPDATE ON MY_TABLE TO SOME_USER,
ANOTHER_USER;
2. REVOKE - The REVOKE command in SQL is defined to take away the
granted privileges from the user of the database. The one who has the authority
to withdraw the privileges in the database administrator.
Syntax : REVOKE SELECT, UPDATE ON MY_TABLE FROM USER1,
USER2;

e) Transaction Control Language

TCL also known as transaction control language includes commands that deals
with the transaction within a database

List of TCL commands:


1) Commit: Commit command is used to save all the transactions
to the database.
Syntax : COMMIT;
2) Rollback: Rollback command is used to undo transactions that
have not already been saved to the database.
Syntax : ROLLBACK;
3) SAVEPOINT: It is used to roll the transaction back to a certain point
without rolling back the entire transaction.
Syntax : SAVEPOINT SAVEPOINT_NAME;
4) SET TRANSACTION: Specify characteristics for the transaction.
Foreword 2
EXPERIMENT NO: 1 Introduction to MYSQL
AIM:To study about Mysql database

THEORY:
MySQL, is one of the most popular Open Source SQL database management
systems.
MySQL is a fast, easy-to-use RDBMS being used for many small and big
businesses.
MySQL is developed, marketed, and supported by MySQL AB, which is a
Swedish company.

MySQL is becoming so popular because of many good reasons:


MySQL is released under an open-source license. So you have
nothing to pay to use it.
MySQL is a very powerful program in its own right. It handles a
large subset of the functionality of the most expensive and powerful
database packages.
MySQL uses a standard form of the well-known SQL data language.
MySQL works on many operating systems and with many
languages including PHP, PERL, C, C++, JAVA, etc. MySQL works very quickly
and works well even with large data sets.
MySQL is very friendly to PHP, the most appreciated language for web
development.
MySQL supports large databases, up to 50 million rows or more in a table.
MySQL is customizable.
RESULT: The mysql database is studied
EXPERIMENT NO: 2
DATA DEFINITION LANGUAGE (DDL)
COMMANDS
AIM:
Consider the database for an organization. Write the queries for the
following

(i) create the database


(ii) select the current database
(iii) Create the following tables.
a) employee (emp_no,emp_name,DOB, address, doj,
mobile_no, dept_no, salary).
b) department (dept_no, dept_name, location).

(iv) Include necessary constraints.


(v) List all the tables in the current database
(vi) Display the structure of the employee table
(vii) Add a new column Designation to the employee table.
(viii) Drop the column location from Dept table
(ix) Drop the tables
(x) Delete the database

OBJECTIVES: To understand the DDL commands

DATABASE QUERIES:
Before creating any tables, MySQL requires you to create a database by
executing the CREATE DATABASE command.
Create a database
CREATE DATABASE <database

name>; Delete a database

DROP DATABASE <database

name>; Select the database

USE <database

name>; List all databases

SHOW

databases; Rename a

database

ALTER DATABASE <database name> RENAME <new database name>

TABLE QUERIES:
To Create a table
CREATE TABLE (<fieldname>< fieldtype>(<fieldsize) ,
…) ; List all tables in the current database
SHOW tables;
Show table format with column names and data
types DESCRIBE <table name>;
Modify the structure of table
ALTER TABLE <table name><alter specifications>;
ALTER TABLE < table name> DROP COLUMN <column name>;
ALTER TABLE <table name> ADD
COLUMN<column name><datatype>(<Size>);
Delete the table

DROP TABLE <tablename


CONSTRAINTS:
Primary key A PRIMARY KEY constraint for a table enforces the table
to accept unique data for a specific column and this constraint create
a unique index for accessing the table faster
UNIQUE The UNIQUE constraint in Mysql does not allow inserting
a duplicate value in a column.

NOT NULL In Mysql NOT NULL constraint allows to specify that a


column can not contain any NULL value.

FOREIGN KEY A FOREIGN KEY in mysql creates a link between two


tables by one specific column of both tables. The specified column in
one table must be a PRIMARY KEY and referred by the column of
another table known as FOREIGN KEY.

CHECK The CHECK constraint determines whether the value is valid


or not from a logical expression.

DEFAULT While inserting data into a table, if no value is supplied to


a column, then the column gets the value set as DEFAULT

PROCEDURE:
(i) CREATE DATABASE
command
(ii)USE DATABASE command
(iii) CREATE TABLE command

(iv) PRIMARY KEY,NOT NULL etc


(v) SHOW TABLES command
(vi) DESCRIBE TABLE command

(vii) ALTER TABLE command


(viii) ALTER TABLE command
(ix) DROP TABLE command

(x) DROP DATABASE command


Code and Output:
Code for (i)-(iv)

(i) create database

organization;

(ii) use organization;

(iii)
(a) create table Department(dept_no int(5) primary
key not null unique,dept_name varchar(30) not
null,location varchar(30) not null);

(b) create table Employee(emp_no int(5) primary


key not null unique,emp_name varchar(30)
not null,DOB date not null,doj date not
null,mobile_no varchar(10) not null,dept_no
int(5),foreign key(dept_no) references
department(dept_no),salary float(10) not null);

(v) show tables


alter table employee add column Designation
varchar(20);

alter table department drop column location;


drop table employee,department;
(x)drop database organization;

PROBLEMS
1. Consider the database for a college and design an ER diagram.
Write the query for the following.
• Create the tables:
Student (sid, sname, sex, dob,dno)
Department (dno, dname)
Faculty (F_id, fname, designation, salary,dno)
Course (cid, cname, credits,dno)
Register (sid,cid,sem ) Teaching
(f_id,cid,sem)
Hostel(hid,hname,seats,)
• Include the necessary constraints NOT NULL,
DEFAULT, CHECK, and PRIMARY KEY, UNIQUE.
• Create a database college.
• Use college as the current database
• Display all the tables in college database
• Describe the structure of all tables
• Modify the student table to add a new field
‘grade’
ER Diagram
2) Consider the database for a banking enterprise. Write the
queries for the below questions.

Create the following tables


Table Attributes

Customer cid,cname,loc,sex,dob

Bank Brn Bcode,bloc,bsate


Deposit Dacno,dtype,ddate,damt

Loan Lacno,ltype,ldate,lamt

Account in Bcode,cid

Depositor cid,dacno

Borrower cid,lacno
● Include necessary constraints.
● Tables are created under the database ‘bank’
● Display all the tables in bank database
● Describe the structure of all tables
Output:
EXPERIMENT NO 3

DATA MANIPULATION LANGUAGE(DML)

AIM:
Consider the database for an organization. Write the queries
for the following

(i) Add 5 rows in the employee and dept tables


(ii) Display all the records from the above tables
(iii) Display the empno and name of all the employees from
department no2.
(iv) Display empno,name,designation,dept
no and salary in the descending order of
salary.
(v) Display the empno and name of all
employees whose salary is between 2000 and
5000.
(vi) Display all designations without
duplicate values.
(vii) Display the dept name and total salary of
employees of each department.
Change the salary of employees to
25000 whose designation is ‘Typist’
Change the mobile no of employee named ‘john’
Delete all employees whose salaries are equal to Rs.7000
Select the department that has total salary paid for its
employees more than 25000

OBJECTIVES:
To understand how to insert, update and delete data from within a table.
To learn how to retrieve data from a table using
the SELECT statement.

THEORY
INSERT
INSERT INTO tablename VALUES (value1, value2, ..., valuen).
UPDATE
UPDATE <table> SET <field1> = <value1> AND <field2> =
<value2> WHERE <conditions>
DELETE
DELETE FROM <table> WHERE <condition>
SELECT
• Retrieve from all columns
SELECT * FROM <table>
• Retrieve from selected columns
SELECT <column 1>, <column 2> FROM <table>
• Retrieve unique values
SELECT DISTINCT <column name> FROM <table>
• Retrieve data satisfying a given condition
SELECT <columns> FROM <tables> WHERE <condition>

PROCEDURE:
(i) Use insert command
(ii) Use Select command
(iii) Use Select command with where condition
(iv) Use Select command with order by clause
(v) Use Select command with operators
(vi) Use Select command with DISTINCT keyword
(vii) Use Select command with group by clause
(viii) Use Update command
(ix) Use Update command
(x) Use Delete command
(xi) Use select command with group by and having clause

RESULT:
The DML commands are executed successfully.
OUTPUT:
Problems
1. Consider the database for a college. Write the query for the
following. (i)Insert at least 5 tuples into each table.
(ii) List the details of students in the ascending
order of date of birth
(iii) Display the details of students from
computer department
(iv) List the faculties in the descending order of salary
(v)Display the total number of students in each
department
(vi)Display the total number of faculties in each department
with salary greater than 2500
2. Consider the database for a banking enterprise. Write the queries for the
below questions.
(i)Insert at least 5 tuples in each table
(ii)Display the branch details
(iii)List the customers of ‘Mumbai’ city
(iv)List the male customers of ‘Kolkata City
(v) List the state having more than one branch.

(vi) List the deposit schemes provided by the


bank to the customers
(vii) Delete the entire content of any table
OUTPUT:
EXPERIMENT NO:4 SUB QUERIES AND
JOIN

AIM:
Consider the database for the organization and Write the queries for the following

(i) display the empno, name, and salaries for employees whose
average salary is higher than the average salary of the
organization
(ii) Display the details of employees whose salary is equal to the
minimum salary of the organisation.
(iii) Display all the employees whose designation is same as that of ‘Arun’
(iv) display the empno and name of employees who
earn more than any Employee in dept 1.
(v)Display the empno, name, departments that the
departments are same in both the emp and dept
(vi) Display the employee details by
implementing left inner join
(vii)Display employee details by implementing a right outer join

OBJECTIVES
To understand Subqueries and Join in Mysql.

THEORY

NESTED QUERIES:
A subquery is a query within a query. These subqueries can
reside in the WHERE clause, the FROM clause, or the SELECT
clause. The first query in the SQL statement is known as the
outer query. The query inside the SQL statement is known as
the inner query. The inner query is executed first. The output
of an inner query is used as the input for the outer query.
The entire SQL statement is sometimes referred to as a nested
query.

JOINS:
MySQL JOINS are used to retrieve data from multiple tables. A
MySQL JOIN is performed whenever two or more tables are
joined in a SQL statement.
There are three types of MySQL joins:
MySQL INNER JOIN (or sometimes called simple join)
MySQL LEFT OUTER JOIN (or sometimes called LEFT
JOIN)
MySQL RIGHT OUTER JOIN (or sometimes called RIGHT JOIN)
INNER JOIN (simple join)
MySQL INNER JOINS return all rows from multiple tables where the join condition
is met.

Syntax
Select columns from

table1 Inner join

table2

On table1.column=table2.column;

LEFT OUTER JOIN

Another type of join is called a MySQL LEFT OUTER JOIN. This type
of join returns all rows from the LEFT-hand table specified in the
ON condition and only those rows from the other table where the
joined fields are equal.

Syntax
Select columns from

table left join table2

On table1.column=table2.column;

RIGHT OUTER JOIN


Another type of join is called a MySQL RIGHT OUTER JOIN. This type
of join returns all rows from the RIGHT-hand table specified in the
ON condition and only those rows from the other table where the
joined fields are equal.

Syntax
Select columns from table 1
Right join table2
On table1.column=table2.column;

PROCEDURE: To be written by the student

RESULT:
The nested queries and joins are executed successfully.
Code and Output:
● SELECT emp_no,emp_name,salary from
employee WHERE salary>(SELECT
avg(salary)FROM employee);

● SELECT * from employee WHERE salary=(SELECT min(salary)FROM employee);

● SELECT emp_name from employee WHERE


designation=(SELECT designation FROM employee
where emp_name="Arun");

● SELECT emp_name ,emp_no from


employee WHERE salary>(SELECT
max(salary) FROM employee where
dept_no=1);
● select emp_no,emp_name,dept_name from employee,department where
employee.dept_no=department.dept_no;

● select * from employee left inner join department on


employee.dept_no=department.dept_no;

● select * from employee right outer join department on


employee.dept_no=department.dept_no;
Problems

1. Consider the database for a banking enterprise. Write the queries for the
below questions.
(i) List the deposit account number and amount in
which the deposit scheme having maximum deposit is
opened
(ii) List the account number and amount of that savings
bank deposit scheme in which a minimum amount is
deposited.
(iii) List the customers having accounts in

‘Chennai’ branch (iv)List the customers

having more than one account

(v) List the customers having the same name but different account numbers.
(vi) List the customer name that is having maximum
deposit account in bank
(vii) List the customer who has borrowed highest
amount of home

● select Dacno,damt from deposit where damt=(select max(damt) from deposit);

● select Dacno,damt from deposit where damt=(select min(damt) from deposit where
dtype=”savings”);
● select cname,customer.cid,dob from customer inner join accountin on
customer.cid=accountin.cid inner join bankbrn on
accountin.Bcode=bankbrn.Bcode where bankbrn.bloc="Chennai";

● select * from customer inner join accountin on customer.cid=accountin.cid


group by accountin.cid having count(accountin.cid)>1;

● select cname from customer join depositor on customer.cid=depositor.cid


join deposit on depositor.dacno=deposit.Dacno where deposit.damt=(select
max(damt) from deposit);

● select cname from customer join borrower on customer.cid=borrower.cid


join loan on loan.Lacno=borrower.lacno where loan.lamt=(select max(lamt) from
loan group by ltype having ltype="Home loan");
● select * from customer left inner join accountin on
accountin.cid=customer.cid order by customer.cid;

● select * from customer right outer join accountin on


accountin.cid=customer.cid order by customer.cid;

2. Consider the database for a college. Write the queries for the below
questions.

(i) List out the ID, Name and Date of Birth of


students registered for a specific course.
(ii) List out the ID, Name and Date of Birth of
students registered for a specific course,staying in
a specific Hostel.

(iii) List the names of faculties who teach for a specific course.
(iv)Display the student details by implementing left inner
join

(v)Display the student details by implementing a right


outer join

● select student.sid, student. sname, dob from student join register on


register.sid=student.sid join course on course.cid=register.cid where
course.cname="BTech";

● select student.sid,student.sname,dob from student join register on


register.sid=student.sid join course on course.cid=register.cid join
stays_in on stays_in.sid=register.sid join hostel on
stays_in.hid=hostel.hid where course.cname="BCA" and
hostel.hname="AT-8";

● select fname from faculty join teaching on teaching.f_id=faculty.F_id join course


on course.cid=teaching.cid where cname="BTech";
● select * from student left inner join
department on student.dno=department.dno left
inner join stays_in on student.sid=stays_in.sid left
inner join
register on student.sid=register.sid left inner join
on course on register.cid=course.cid;

● select * from student right outer join


department on
student.dno=department.dno right outer
join stays_in on student.sid=stays_in.sid
right outer join
register on student.sid=register.sid right outer
join course on register.cid=course.cid;
EXPERIMENT NO 5

VIEWS
AIM:
Write the queries for the following
(i) Create a view emp from employee such that it
contains only emp_no and emp_name and department.
(ii) Create a view dept from department with only dept_no and location.
(iii) Create a view that contains the details of employees who are managers only.
(iv) drop the views.

OBJECTIVES
To understand views in Mysql

THEORY
A view is the tailored presentation of data contained in one or more
tables and can also be said as a restricted view to the data in the
tables. A view is a “virtual table” or a “stored query” which takes the
output of a query and treats it as a table. The table upon which a
view is created is called a base table. A view is a logical table based
on a table or another view. A view contains no data of its own but
is like a window through which data from tables can be viewed or
changed. The tables on which a view is based are called base tables.
The view is stored as a SELECT statement in the data dictionary.
Advantages of a view:
a. Additional level of table security.
b. Hides data complexity.
c. Simplifies the usage by combining multiple
tables into a single table
Creating and dropping view:
Syntax:
Create or replace view view_name AS SELECT
column_name(s) FROM table_name
WHERE condition;
Drop view <view name>
PROCEDURE:
● Create the employee table
● Create the view
● Display the content of view

CODE FOR QUERIES:

○ create view Emp_details as (select emp_no,emp_name,dept_name from


employee,department where employee.dept_no=department.dept_no);
select * from Emp_details;
○ create view Dept_View as (select department.dept_no,employee.loc from
employee,department where employee.dept_no=department.dept_no);
select * from Dept_View;

○ create view Details as (select * from employee where


designation="Manager"); select * from Details;

Result
Thus the views are created successfully.

Problems
1. Create and drop views on student table

2. Create and drop views on customer and deposit table

2. Ans:-
create view Customer_View as (select cid,cname,dob,loc from customer
where
loc="Delhi");

select * from Customer_View;

drop view Customer_View;

create view Deposit_type as (select * from deposit where dtype="Savings"); select * from

Deposit_type;

drop view Deposit_type;

EXPERIMENT NO:6
PROCEDURE
AIM:
Write a procedure which increases the salary of an employee. It accepts
an employee number and salary increase amount. It uses the employee
number to find the current salary from the EMPLOYEE table and update
the salary.

OBJECTIVES
To understand procedure in Mysql
THEORY

PROCEDURE:

In MySQL, a procedure is a stored program that you can pass


parameters into. It does not return a value like a function does.

Syntax
Create procedure procedure name (parameter data type, parameter
data type...) Begin
Declaration
section
Executable
_section End;
Procedure name
The name to assign to this procedure in MySQL.

Parameter

When creating a procedure, there are three types of parameters that can be declared:
1. IN - The parameter can be referenced by the procedure. The value
of the parameter cannot be overwritten by the procedure.
2. OUT - The parameter cannot be referenced by the procedure, but
the value of the parameter can be overwritten by the procedure.
3. IN OUT - The parameter can be referenced by the procedure and
the value of the parameter can be overwritten by the procedure.

Declaration section
The place in the procedure where you declare local variables.
Executable section
The place in the procedure where you enter the code for the procedure.

PROCEDURE:

i.)Write the procedure with empno and increment


name as parameter
ii.)Use update command to increment salary
CODE
use organization;

CREATE PROCEDURE IncSalary(IN emp_num


int,IN sal int) BEGIN
update employee set salary=salary+sal where
emp_no=emp_num;
END;
call IncSalary(2,5000);

OUTPUT:Salary of emp_no 2 changed to 20,000 from 25,000


RESULT:
The procedures are executed successfully.

Problems

1. Write a procedure which accepts the account number of a


customer and retrieve the balance.
2. Write a procedure which accepts the student number and
displays the department in which he belongs to.
Answers-
USE Bank;
1. DELIMITER //
CREATE PROCEDURE getbalance(IN
acno int) BEGIN
select Dacno,damt as balance from deposit where Dacno=acno;
END //

DELIMITER ;
call getbalance(23212);

OUTPUT:
2.

Ans-

use college;

DELIMITER //

CREATE PROCEDURE getdept(IN

sno int) BEGIN

select department.dname from department join student


on student.dno=department.dno where student.sid=sno;

END //

DELIMITER ;

call getdept(3);

OUTPUT
EXPERIMENT NO:7
CURSORS
AIM
Write a cursor to display the list of employees who are working as managers.

OBJECTIVES
To implement cursor

THEORY
A cursor is a SELECT statement that is defined within the declaration section
of your stored program in MySQL.
1. Declare a cursor
Declare cursor name cursor for select statement;
2. Open the cursor.
Open cursor name;
3. Fetch cursor
The purpose of using a cursor, in most cases, is to retrieve the rows from your
cursor so that some type of operation can be performed on the data. Fetch cursor
name into variable list;
4 . Close the cursor
Close cursor name;

PROCEDURE

Code & Output


RESULT
The cursor is executed successfully.

PROGRAMS
1 . Create a cursor to modify the salary of ‘Professors’ belonging to all
departments by 150%.
2. Consider the college database. Retrieve all students who have registered
for a specific course and store their details into another table using cursors.

3 . Consider the bank database. Retrieve all customers who have a loan at a
particular branch using a cursor.
EXPERIMENT NO:8
TRIGGER
AIM
Write a Trigger for employee table it will store the updated salary into
another
table SALARY while updating salary.

OBJECTIVES
To understand triggers in Mysql

THEORY.
A trigger is a set of actions that are run automatically when a specified
change operation
( INSERT, UPDATE, or DELETE statement) is performed on a specified table.
The syntax to
create an AFTER UPDATE Trigger in MySQL is:
Create trigger trigger_nane
After update On table name for each row
Begin Variable declarations
Trigger code
End;

PROCEDURE
(i) Create the employee table
(ii) Insert values
(iii) Write the after update trigger
(iv) Update the salary in employee table
(v) Display the SALARY table
CODE & OUTPUT
RESULT
The trigger procedure has been executed successfully.

Problems 1. Write an update trigger on the Account table. The system should
keep track of the records that are being updated.
Problem 2. Write a before delete trigger on the Student table.
Experiment No: 9
CONCEPTS OF NORMALIZATION
AIM
Checking Normalization of a database table (First Normal form)

Problem Statement
An exercise to check whether the given database table is normalized or not.
If yes, find out the status of normalization and reasoning .

Objective
To study the concept of various levels of normalization and understand how
to convert
into normalized forms.

Requirements
Mysql database software

Design/Theory
Create a database table in SQL with a few rows and columns. Analyze the
table
and determine to which normal form it belongs to according to the rules and
regulations of each normal form.

Procedure
Consider a student table as given below.

We can easily verify that this table satisfies 1NF: viz, it has duplicate rows;
each cell is a single-valued(i.e there is no repeating group of arrays); and all
the entries in the given column are of the same kind. In this table we can see
that the key, SSN, functionality determines the other attributes; i.e
FirstName, LastName and Major.

Experiment No: 10
AIM
Checking Normalization of a database table (Third normal form).

Problem Statement
An exercise to check whether the given database table is normalized or not.
If yes ,find out the status of normalization and reasoning.

Objective
To study the concept of various levels of normalization and understand how
to convert into normalized forms.

Requirements
Mysql database software

Design/Theory
Create a database table in SQL with a few no of rows and columns.Analyze
the table
and determine to which normal form it belongs to according to the rules and
regulations of each normal form.

Procedure
Consider a book database table as given below.
By examining the table, we can infer that books dealing with history,
cognitive psychology, and folksong are assigned to the PCL General Stacks
collection; that books dealing with legal procedures are assigned to the Law
Library; that books dealing with Greek literature are assigned to the Classics
Library; that books dealing with library biography are assigned to the Library
and Information Science Collection (LISC); and that books dealing with
music literature are assigned to the Fine Arts Library.

Moreover, we can infer that the PCL General Stacks collection and the LISC
are both housed in the Perry-Castañeda Library (PCL) building; that the
Classics Library is housed in Waggener Hall; and that the Law Library and
Fine Arts Library are housed, respectively, in Townes Hall and the Fine Arts
Building.

Thus we can see that a transitive dependency exists in the above table : any
book that deals with history, cognitive psychology, or library biography will
be physically housed in the PCL building (unless it is temporarily checked
out to a borrower); any book dealing with legal procedures will be housed in
Townes Hall; and so on. In short, if we know what subject a book deals with,
we also know not only what library or collection it will be assigned to but
also what building it is physically housed in.

A problem with transitive dependency is that there is duplicated


information: from three different rows we can see that the PCL General
Stacks are in the PCL building. For another thing, we have possible deletion
anomalies: if the Yudof book were lost and its row removed from the table,
we would lose the information that books on legal procedures are assigned
to the Law Library and also the information the Law Library is in Townes
Hall. As a third problem, we have possible insertion anomalies: if we wanted
to add a chemistry book to the table, we would find that the above table
nowhere contains the fact that the Chemistry Library is in Robert A.Welch
Hall. As a
Fourth problem, we have the chance of making errors in updating: a careless
data-entry clerk might add a book to the LISC but mistakenly enter Townes
Hall in the building column.
To solve this problem decompose the above table into three different tables
as follows

You might also like