database management systems - chdl lab manual.pdf · lab manual for database management systems...
TRANSCRIPT
CREC, Dept. of CSE Page 1
LAB MANUAL
For
DATABASE MANAGEMENT SYSTEMS
B.TECH CSE II YEAR I SEMESTER
(JNTUA-R15)
Mrs. S.RUKSANA M.Tech
Assistant Professor
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
CHADALAWADA RAMANAMMA ENGINEERING COLLEGE CHADALAWADA NAGAR,
RENIGUNTA ROAD, TIRUPATI (A.P) - 517506
CREC, Dept. of CSE Page 2
JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY ANANTAPUR
B. Tech II - I sem (Common to CSE & IT) T Tu C 3 1 3
(15A05303) DATABASE MANAGEMENT SYSTEMS LABORATORY
Course Objectives:
To create a database and query it using SQL, design forms and generate reports. Understand the significance of integrity constraints, referential integrity constraints, triggers, assertions.
Course Outcomes:
Design databases Retrieve information from data bases Use procedures to program the data access and manipulation Create user interfaces and generate reports
List of Experiments:
1. Practice session: Students should be allowed to choose appropriate DBMS software, install it, configure it and start working on it. Create sample tables, execute some queries, use SQLPLUS features, use PL/SQL features like cursors on sample database. Students should be permitted to practice appropriate User interface creation tool and Report generation tool.
2. A college consists of number of employees working in different departments. In this context, create two tables employee and department. Employee consists of columns empno, empname, basic, hra, da, deductions, gross, net, date-of-birth. The calculation of hra,da are as per the rules of the college. Initially only empno, empname, basic have valid values. Other values are to be computed and updated later. Department contains deptno, deptname, and description columns. Deptno is the primary key in department table and referential integrity constraint exists between employee and department tables. Perform the following operations on the the database:
Create tables department and employee with required constraints.
Initially only the few columns (essential) are to be added. Add the remaining columns separately by using appropriate SQL command
Basic column should not be null
Add constraint that basic should not be less than 5000.
Calculate hra,da,gross and net by using PL/SQL program.
Whenever salary is updated and its value becomes less than 5000 a trigger has to be raised preventing the operation.
The assertions are: hra should not be less than 10% of basic and da should not be less than 50% of basic.
The percentage of hra and da are to be stored separately.
When the da becomes more than 100%, a message has to be generated and with user permission da has to be merged with basic.
Empno should be unique and has to be generated automatically.
If the employee is going to retire in a particular month, automatically a message has to be generated.
The default value for date-of-birth is 1 jan, 1970.
When the employees called daily-wagers are to be added the constraint that salary should be greater than or equal to 5000 should be dropped.
Display the information of the employees and departments with description of the fields.
Display the average salary of all the departments.
Display the average salary department wise.
Display the maximum salary of each department and also all departments put together.
Commit the changes whenever required and rollback if necessary.
Use substitution variables to insert values repeatedly.
Assume some of the employees have given wrong information about date-of-birth. Update the corresponding tables to change the value.
CREC, Dept. of CSE Page 3
Find the employees whose salary is between 5000 and 10000 but not exactly 7500.
Find the employees whose name contains ‘en’.
Try to delete a particular deptno. What happens if there are employees in it and if there are no employees.
Create alias for columns and use them in queries.
List the employees according to ascending order of salary.
List the employees according to ascending order of salary in each department.
Use ‘&&’ wherever necessary
Amount 6000 has to be deducted as CM relief fund in a particular month which has to be accepted as input from the user. Whenever the salary becomes negative it has to be maintained as 1000 and the deduction amount for those employees is reduced appropriately.
The retirement age is 60 years. Display the retirement day of all the employees.
If salary of all the employees is increased by 10% every year, what is the salary of all the employees at retirement time.
Find the employees who are born in leap year.
Find the employees who are born on feb 29.
Find the departments where the salary of atleast one employee is more than 20000.
Find the departments where the salary of all the employees is less than 20000.
On first January of every year a bonus of 10% has to be given to all the employees. The amount has to be deducted equally in the next 5 months. Write procedures for it.
As a designer identify the views that may have to be supported and create views.
As a designer identify the PL/SQL procedures necessary and create them using cursors.
Use appropriate Visual programming tools like oracle forms and reports, visual basic etc to create user interface screens and generate reports.
Note: As a designer identify other operations that may be required and add to the above list. The above operations are not in order. Order them appropriately. Use SQL or PL/SQL depending on the requirement.
3. Students may be divided into batches and the following experiments may be given to them to better understand the DBMS concepts. Students should gather the required information, draw ER diagrams, map them to tables, normalize, create tables, triggers, procedures, execute queries, create user interfaces, and generate reports.
Student information system
APSRTC reservation system
Hostel management
Library management
Indian Railways reservation
Super market management
Postal system
Banking system
Courier system
Publishing house system
References:
1. “Oracle Database 11g PL/SQL Programming”, M.Mc Laughlin,TMH.
2. “Learning Oracle SQL and PL/SQL”, Rajeeb C. Chatterjee, PHI.
3. “Introduction to SQL”, Rick F.Vander Lans, Pearson education.
4. “Oracle PL/SQL”, B.Rosenzweig and E.Silvestrova, Pearson education.
CREC, Dept. of CSE Page 4
1. Practice session: Students should be allowed to choose appropriate DBMS software, install it, configure it and start working on it. Create sample tables, execute some queries, use SQLPLUS features, use PL/SQL features like cursors on sample database. Students should be permitted to practice appropriate User interface creation tool and Report generation tool.
1. Select installation method
Following two installation methods are available:
Basic Installation – Choose this to perform the full Oracle Database 11g installation with standard configuration options. You can use only filesystem for storage in this option.
Advanced Installation – This gives your full control over the installation, including the ability to choose Automatic Storage Management. Select this option as shown below.
Fig – Select Installation Method (Click on the image to enlarge it)
2. Specify Inventory directory and credentials
Enter the following information:
Enter the inventory directory: /u01/app/oraInventory Specify operating system group name: oinstall
Fig – Specify Inventory directory and credentials (Click on the image to enlarge it)
3. Select Installation Type
Following three installation types are available:
Enterprise Edition – Select this option. Standard Edition Custom
CREC, Dept. of CSE Page 5
Fig – Select Installation Type (Click on the image to enlarge it)
4. Specify Install Location
Enter the following information:
Oracle Base: /u01/app/oracle Name: Oracle_Home Path: /u01/app/oarcle/product/11.1.0
Fig – Select Install Location (Click on the image to enlarge it)
5. Product-Specific Prerequisite Checks
In this screen, the Installer verifies that your environment meets all of the minimum requirements for installing and configuring the products that you have chosen to install. You must manually verify and confirm the items that are flagged with warnings and items that require manual checks.
6. Select Configuration Option
Following three configuration options are available:
Create a Database – Select this option.
Configure Automatic Storage Management (ASM) Install Software Only
CREC, Dept. of CSE Page 6
Fig – Select Configuration Option (Click on the image to enlarge it)
7. Select a Database Configuration
Following three database configuration options are available.
General Purpose/Transaction Processing – Select this option. Data Warehouse Advance
Fig – Select Database Configuration (Click on the image to enlarge it)
8. Specify Database Configuration
Enter the following information:
Global Database Name: devdb.example.com . An Oracle database is uniquely identified by a Global Database Name, typically of the form “name.domain”
SID: devdb
9. Specify Database Configuration Details
There are four different tabs in this screen as shown below:
Memory Tab o Select the check-box to Enable Automatic Memory Management o Drag the bar to allocate the memory. This will automatically allocate memory size for SGA and PGA
depending on the total database memory allocated. Character Sets Tab. Following three character set options are given in this tab.
o Use the default o Use Unicode (AL32UTF8) o Choose from the list of character sets. Select Database Character Set as Unicode standard UTF-
8AL32UTF8 – Select this option. Security Tab – Just leave the defaults in this tab. Sample Schema Tab – Just leave the defaults in this tab.
CREC, Dept. of CSE Page 7
Fig – Select Database Config Details with Memory Tab (Click on the image to enlarge it)
10. Select Database Management Option
Following two management options are available:
Use Grid Control for Database Management o Management Service: Choose an agent.
Use Database Control for Database Management- Select this option. o Select the check-box to Enable Email Notifications o Outgoing mail (SMTP) Server: o Email Address:
Fig – Select Database Management Option (Click on the image to enlarge it)
11. Specify Database Storage Option
Following two storage options are available:
File System – Select this option. o Specify Database File location: /u01/app/oracle/oradata/
Automatic Storage Management. ASM simplifies database storage administration and optimizes database layout for I/O performance.
12. Specify Backup and Recovery Option
Enable automated backup as shown below. If you’ve configured ASM, you can choose to store the automated backups on
ASM. If not, select File System option.
CREC, Dept. of CSE Page 8
Fig – Specify Backup and Recovery Options (Click on the image to enlarge it)
13. Specify database schema password
Enter the password for sys, system, sysman, dbsnmp schemas. You have the option of either using the same passwords or different password for all the accounts in this screen.
14. Privileged Operating System Groups
Enter the following information in this screen:
Database Administrator (OSDBA) Group: dba Database Operator (OSOPER) Group: dba ASM administrator (OSASM) Group: dba
15. Oracle Configuration Manager Registration
You can associate your configration information with your metalink account as shown below.
Fig – Oracle Configuration Manager Registration (Click on the image to enlarge it)
16. Final Summary Screen
This will display a summary of all the installation option you’ve selected so far. Click on Install to complete the
installation.
Fig – Installation Summary Screen (Click on the image to enlarge it)
CREC, Dept. of CSE Page 9
2. A college consists of number of employees working in different departments. In this context, create two tables employee and department. Employee consists of columns empno, empname, basic, hra, da, deductions, gross, net, date-of-birth. The calculation of hra,da are as per the rules of the college. Initially only empno, empname, basic have valid values. Other values are to be computed and updated later. Department contains deptno, deptname, and description columns. Deptno is the primary key in department table and referential integrity constraint exists between employee and department tables. Perform the following operations on the the database:
2.1 Create tables department and employee with required constraints.
SQL> create table dept(did number primary key, dname varchar(10),dhod varchar(10));
Table created.
SQL> select * from dept;
DID DNAME DHOD
---------- ---------- ----------
101 cse rama
102 cse muni
103 cse munnaiah
104 ece trimurt
105 eee siva
SQL> create table emp1(eid number primary key,ename varchar(10),basic number, hra number, da number, gross
number, net number, dob date,did references dept(did));
Table created.
SQL> select * from emp1;
EID ENAME BASIC HRA DA GROSS NET
---------- ---------- ---------- ---------- ---------- ---------- ----------
DOB DID
--------- ----------
1001 ruks 14000 200 300 200 300
16-JUL-93 101
1002 veena 15000 400 100 200 300
20-JUL-93 102
1003 endira 18000 400 300 400 600
20-JUN-93 103
CREC, Dept. of CSE Page 10
2.2 Initially only the few columns (essential) are to be added. Add the remaining columns separately by using appropriate SQL command
SQL> alter table dept add droom number;
Table altered.
2.3 Basic column should not be null
SQL> alter table emp1 modify basic not null;
Table altered.
2.4 Add constraint that basic should not be less than 5000
SQL> alter table emp1 add constraint chk5 check(basic>5000);
Table altered.
2.5 Calculate hra,da,gross and net by using PL/SQL program.
create or replace procedure daprocedure as
cursor c is select * from emp;
ch char(2) :='&ch';
begin
for i in c loop
if i.da=i.basic then
dbms_output.put_line('do u wanna merge da with basic');
if (ch ='y') or (ch ='y') then
update emp set i.da=i.basic where empno=i.empno;
end if;
end if;
end loop;
end;
/ Procedure created
CREC, Dept. of CSE Page 11
2.6 Whenever salary is updated and its value becomes less than 5000 a trigger has to be raised preventing the operation.
create or replace trigger trname before update on emp1
for each row
declare
begin
if :new.basic<5000 then
raise_application_error(-20000,'basic cant be less than 5000');
end if;
end;
/
Trigger created.
2.7 The assertions are: hra should not be less than 10% of basic and da should not be less than 50% of basic.
SQL> alter table emp1 add constraint chk6 check(hra>0.01*basic);
Table altered.
SQL> alter table emp1 add constraint chk7 check(da>0.005*basic);
Table altered.
2.8 The percentage of hra and da are to be stored separately.
SQL> alter table emp1 add phra1 number;
Table altered.
SQL> alter table emp1 add pda number;
Table altered.
2.10 Empno should be unique and has to be generated automatically.
declare
cursor c is select * from emp1;
k number:=1;
begin
for i in c
loop
CREC, Dept. of CSE Page 12
update emp1 set eid=100||k where eid=i.eid;
k:=k+1;
end loop;
end;
/
2.11 If the employee is going to retire in a particular month, automatically a message has to be generated
declare
cursor c is select months_between(sysdate,dob)/12 from emp;
begin
for i in c loop
if round(i.d)>60 then
dbms_output.put_line('u are going to retire this month');
end if;
end loop;
end;
/
u are going to retire this month
2.12 The default value for date-of-birth is 1 jan, 1970
SQL> alter table emp1 modify dob date default '01-jan-1970';
Table altered.
2.13 When the employees called daily-wagers are to be added the constraint that salary should be greater than or equal to 5000 should be dropped.
SQL> alter table emp1 add constraint chk8 check(basic>=5000);
Table altered.
SQL> alter table emp1 drop constraint chk8;
Table altered.
2.14 Display the information of the employees and departments with description of the fields.
SQL> desc emp1;
CREC, Dept. of CSE Page 13
Name Null? Type
----------------------------------------- -------- ----------------------------
EID NOT NULL NUMBER
ENAME VARCHAR2(10)
BASIC NOT NULL NUMBER
HRA NUMBER
DA NUMBER
GROSS NUMBER
NET NUMBER
DOB DATE
DID NUMBER
PHRA NUMBER
DOJ DATE
PHRA1 NUMBER
PDA NUMBER
DNAME VARCHAR2(10)
YROFBIRTH NUMBER
SQL> desc dept;
Name Null? Type
----------------------------------------- -------- ----------------------------
DID NOT NULL NUMBER
DNAME VARCHAR2(10)
DHOD VARCHAR2(10)
DROOM NUMBER
2.15 Display the average salary of all the departments.
SQL> select avg(basic) from emp1;
AVG(BASIC)
----------
15666.6667
2.16 Display the average salary department wise.
SQL> select avg(basic) from emp1 group by dname;
CREC, Dept. of CSE Page 14
AVG(BASIC)
----------
14500
18000
2.17 Display the maximum salary of each department and also all departments put together.
SQL> select max(basic) from emp1 group by dname;
MAX(BASIC)
----------
15000
18000
SQL> select max(basic) from emp1 ;
MAX(BASIC)
----------
18000
2.18 Commit the changes whenever required and rollback if necessary.
SQL> commit;
Commit complete.
SQL> rollback;
Rollback complete.
2.19 Use substitution variables to insert values repeatedly.
SQL> insert into dept values(&did,'&dname','&dhod',&droom);
Enter value for did: 111
Enter value for dname: eee
Enter value for dhod: siva
Enter value for droom: 301
CREC, Dept. of CSE Page 15
old 1: insert into dept values(&did,'&dname','&dhod',&droom)
new 1: insert into dept values(111,'eee','siva',301)
1 row created.
2.20 Assume some of the employees have given wrong information about date-of-birth. Update the corresponding
tables to change the value.
SQL> update emp1 set dob='23-feb-2012' where eid=1003;
0 rows updated.
2.21 Find the employees whose salary is between 5000 and 10000 but not exactly 7500.
SQL> select ename from emp1 where basic between 5000 and 10000 and basic not in(7500);
no rows selected.
2.22 Find the employees whose name contains ‘en’.
SQL> select ename from emp1 where ename like '%en%';
ENAME
----------
veena
endira
2.23 Try to delete a particular deptno. What happens if there are employees in it and if there are no employees
SQL> delete from emp1 where did=20;
If the employees are there in the department referential integrity constraint violates and you cannot drop it without dropping corresponding employee entries.
If there are no employees then you can do delete the data.
2.24 Create alias for columns and use them in queries.
SQL> select (basic+500) "bonus" from emp1 ;
bonus
----------
14500
15500
CREC, Dept. of CSE Page 16
18500
2.25List the employees according to ascending order of salary.
SQL> select ename from emp1 order by basic asc;
ENAME
----------
ruks
veena
endira
2.26 The retirement age is 60 years. Display the retirement day of all the employees.
SQL> select add_months(dob,60*12) "Retirement Day" from emp1;
Retirement
---------
29-FEB-76
20-JUL-53
20-JUN-53
2.27 If salary of all the employees is increased by 10% every year, what is the salary of all the employees at retirement time.
SQL> select ((basic+basic*0.1)*months_between(sysdate,doj)/12)"salary at retirement" from emp1;
salary at retirement
--------------------
111009.18
133211.016
2.28 Find the employees who are born in leap year.
SQL> select ename FROM emp1 where mod(to_number(to_char(dob,'YYYY')),4)=0 and
mod(to_number(to_char(dob,'YYYY')),100)!=0 or mod(to_number(to_char(dob,'YYYY')),400)=0;
ENAME
----------
Ruks
CREC, Dept. of CSE Page 17
2.29 Find the employees who are born on feb 29.
SQL> select ename from emp1 where to_char(dob,'mon dd')='feb 29';
ENAME
----------
Ruks
2.30 Find the departments where the salary of atleast one employee is more than 20000.
SQL> select dname from dept where did in (select e.did from emp1 e,emp1 ee where e.basic>ee.basic);
DNAME
----------
cse
2.31 Find the departments where the salary of all the employees is less than 20000.
SQL> select ename from emp1 where basic>20000;
no rows selected
2.32 As a designer identify the views that may have to be supported and create views.
SQL> create view eview as select ename, eid,did from emp1;
View created.
2.33 As a designer identify the views that may have to be supported and create views. On first January of every year a bonus of 10% has to be given to all the employees. The amount has to be deducted equally in the next 5 months. Write procedure.
create or replace procedure salded as
cursor c is select * from emp1;
begin
for i in c
loop
if to_char(sysdate,'mon dd')='jan 01' then
update emp1 set basic=i.basic+i.basic*0.1 where eid=i.eid;
end if ;
if to_char(sysdate,'mon dd')='feb 01' then
CREC, Dept. of CSE Page 18
update emp1 set basic=i.basic-i.basic*0.02 where eid=i.eid;
end if;
if to_char(sysdate,'mon dd')='mar 01' then
update emp1 set basic=i.basic-i.basic*0.02 where eid=i.eid;
end if;
if to_char(sysdate,'mon dd')='apr 01' then
update emp1 set basic=i.basic-i.basic*0.02 where eid=i.eid;
end if;
if to_char(sysdate,'mon dd')='may 01' then
update emp1 set basic=i.basic-i.basic*0.02 where eid=i.eid;
end if;
if to_char(sysdate,'mon dd')='jun 01' then
update emp1 set basic=i.basic-i.basic*0.02 where eid=i.eid;
end if;
end loop;
end;
/
Procedure created.
2.34 As a designer identify the PL/SQL procedures necessary and create them using cursors.
create or replace procedure salded as
cursor c is select * from emp1;
begin
for i in c
loop
if to_char(sysdate,'mon dd')='jan 01' then
update emp1 set basic=i.basic+i.basic*0.1 where eid=i.eid;
end if ;
if to_char(sysdate,'mon dd')='feb 01' then
update emp1 set basic=i.basic-i.basic*0.02 where eid=i.eid;
end if;
if to_char(sysdate,'mon dd')='mar 01' then
update emp1 set basic=i.basic-i.basic*0.02 where eid=i.eid;
end if;
if to_char(sysdate,'mon dd')='apr 01' then
update emp1 set basic=i.basic-i.basic*0.02 where eid=i.eid;
end if;
if to_char(sysdate,'mon dd')='may 01' then
update emp1 set basic=i.basic-i.basic*0.02 where eid=i.eid;
CREC, Dept. of CSE Page 19
end if;
if to_char(sysdate,'mon dd')='jun 01' then
update emp1 set basic=i.basic-i.basic*0.02 where eid=i.eid;
end if;
end loop;
end;
/
Procedure created
3. Students may be divided into batches and the following experiments may be given to them to better understand the DBMS concepts. Students should gather the required information, draw ER diagrams, map them to tables, normalize, create tables, triggers, procedures, execute queries, create user interfaces, and generate reports.
3.1 Student information system
Student Result
Unit enrolment
Unit Unit offering has
enrolls
is given
Student has Course
contains
is enrolled
in
Department
Faculty
belongs to
offered
by
runs
Room requirements
Resource
requirements
Room allocations
Staff allocations
comprises Special
consideration application
Grading rules
changes
Assignment result
Exam result
based
on
lodges
needs needs is taught in
is taught
by
CREC, Dept. of CSE Page 20
3.2 Library management
NORMALIZATION OF DATABASE:
Database Normalisation is a technique of organizing the data in the database. Normalization is a systematic approach of
decomposing tables to eliminate data redundancy and undesirable characteristics like Insertion, Update and Deletion
Anamolies. It is a multi-step process that puts data into tabular form by removing duplicated data from the relation tables.
Normalization is used for mainly two purpose,
Eliminating reduntant(useless) data.
Ensuring data dependencies make sense i.e data is logically stored.
Problem Without Normalization
Without Normalization, it becomes difficult to handle and update the database, without facing data loss. Insertion,
Updation and Deletion Anamolies are very frequent if Database is not Normalized. To understand these anomalies let us
take an example of Student table.
CREC, Dept. of CSE Page 21
S_id S_Name S_Address Subject_opted
401 Adam Noida Bio
402 Alex Panipat Maths
403 Stuart Jammu Maths
404 Adam Noida Physics
Updation Anamoly : To update address of a student who occurs twice or more than twice in a table, we will have to
update S_Address column in all the rows, else data will become inconsistent.
Insertion Anamoly : Suppose for a new admission, we have a Student id(S_id), name and address of a student but if
student has not opted for any subjects yet then we have to insert NULL there, leading to Insertion Anamoly.
Deletion Anamoly : If (S_id) 401 has only one subject and temporarily he drops it, when we delete that row, entire
student record will be deleted along with it.
Normalization Rule
Normalization rule are divided into following normal form.
1. First Normal Form
2. Second Normal Form
3. Third Normal Form
4. BCNF
First Normal Form (1NF)
As per First Normal Form, no two Rows of data must contain repeating group of information i.e each set of column must
have a unique value, such that multiple columns cannot be used to fetch the same row. Each table should be organized into
rows, and each row should have a primary key that distinguishes it as unique.
The Primary key is usually a single column, but sometimes more than one column can be combined to create a single
primary key. For example consider a table which is not in First normal form
CREC, Dept. of CSE Page 22
Student Table :
Student Age Subject
Adam 15 Biology, Maths
Alex 14 Maths
Stuart 17 Maths
In First Normal Form, any row must not have a column in which more than one value is saved, like separated with
commas. Rather than that, we must separate such data into multiple rows.
Student Table following 1NF will be :
Student Age Subject
Adam 15 Biology
Adam 15 Maths
Alex 14 Maths
Stuart 17 Maths
Using the First Normal Form, data redundancy increases, as there will be many columns with same data in multiple rows
but each row as a whole will be unique.
Second Normal Form (2NF)
As per the Second Normal Form there must not be any partial dependency of any column on primary key. It means that for
a table that has concatenated primary key, each column in the table that is not part of the primary key must depend upon
the entire concatenated key for its existence. If any column depends only on one part of the concatenated key, then the
table fails Second normal form.
In example of First Normal Form there are two rows for Adam, to include multiple subjects that he has opted for. While
this is searchable, and follows First normal form, it is an inefficient use of space. Also in the above Table in First Normal
Form, while the candidate key is {Student, Subject}, Age of Student only depends on Student column, which is incorrect
CREC, Dept. of CSE Page 23
as per Second Normal Form. To achieve second normal form, it would be helpful to split out the subjects into an
independent table, and match them up using the student names as foreign keys.
New Student Table following 2NF will be :
Student Age
Adam 15
Alex 14
Stuart 17
In Student Table the candidate key will be Student column, because all other column i.e Age is dependent on it
New Subject Table introduced for 2NF will be :
Student Subject
Adam Biology
Adam Maths
Alex Maths
Stuart Maths
In Subject Table the candidate key will be {Student, Subject} column. Now, both the above tables qualifies for Second
Normal Form and will never suffer from Update Anomalies. Although there are a few complex cases in which table in
Second Normal Form suffers Update Anomalies, and to handle those scenarios Third Normal Form is there.
Third Normal Form (3NF)
Third Normal form applies that every non-prime attribute of table must be dependent on primary key, or we can say that,
there should not be the case that a non-prime attribute is determined by another non-prime attribute. So this transitive
functional dependency should be removed from the table and also the table must be in Second Normal form. For example,
consider a table with following fields.
CREC, Dept. of CSE Page 24
Student_Detail Table :
Student_id Student_name DOB Street city State Zip
In this table Student_id is Primary key, but street, city and state depends upon Zip. The dependency between zip and other
fields is called transitive dependency. Hence to apply 3NF, we need to move the street, city and state to new table,
with Zip as primary key.
New Student_Detail Table :
Student_id Student_name DOB Zip
Address Table :
Zip Street city state
The advantage of removing transtive dependency is,
Amount of data duplication is reduced.
Data integrity achieved.
Boyce and Codd Normal Form (BCNF)
Boyce and Codd Normal Form is a higher version of the Third Normal form. This form deals with certain type of
anamoly that is not handled by 3NF. A 3NF table which does not have multiple overlapping candidate keys is said to be in
BCNF. For a table to be in BCNF, following conditions must be satisfied:
R must be in 3rd Normal Form
and, for each functional dependency ( X -> Y ), X should be a super Key.
CREC, Dept. of CSE Page 25