DBMS Lab Experiment-Reg
DBMS Lab Experiment-Reg
AIM:
A) To create simple queries with constraints such as primary key, not null, check,
referential integrity.
B) To perform various subqueries and operators.
PROCEDURE:
Step 1: Start
Step 2: Create the table with its essential attributes.
Step 3: Insert attribute values into the table
Step 4: Execute different nested query Commands with constraints and extract
information from the table.
Step 5: Stop
1. NOT NULL:
Used to set the not null constraint to the specified column name which will not allow null
values.
Syntax:
Create table tablename(fieldname1 datatype(constraint)not null,fieldname2 datatype,
…………….fieldnamen datatype);
Example:
SQL> create table notnull (eno varchar2(10) not null,ename varchar2(10),esalary
number(20));
Table created.
1 row created.
SQL> /
Enter value for eno:
Enter value for ename: raj
Enter value for esalary: 30000
old 1: insert into notnull values('&eno','&ename','&esalary')
new 1: insert into notnull values('','raj','30000')
insert into notnull values('','raj','30000')
*
ERROR at line 1:
ORA-01400: cannot insert NULL into ("SCOTT"."NOTNULL"."ENO")
2. CHECK:
Syntax:
Create table tablename(Fieldname1 datatype(constraint),Fieldname2 datatype,
………………….Fieldname3 datatype);
Example:
SQL> create table con( empid varchar2(20) not null,empname varchar2(20),empsalary
number(10) check(empsalary>10000));
Table created.
Syntax:
Create table tablename(fieldname1 datatype(constraint)unique,fieldname2 datatype,
…………….Fieldname3 datatype);
Example:
SQL> create table conn(eno varchar2(10) unique,ename varchar2(20));
Table created.
1 row created.
SQL> /
Enter value for eno: 1
Enter value for ename: hi
old 1: insert into conn values('&eno','&ename')
new 1: insert into conn values('1','hi')
insert into conn values('1','hi')
*
ERROR at line 1:
ORA-00001: unique constraint (SCOTT.SYS_C0010285) violated
4. PRIMARY KEY:
Primary key is a constraint for both unique and not null.
Syntax:
Create table tablename(Fieldname1 datatype(constraint)unique,fieldname2 datatype,
…………….Fieldname3 datatype);
Example:
SQL> create table con(empid varchar2(10),empname varchar2(20) primary key);
Table created.
1 row created.
SQL> /
Enter value for empid: 2
Enter value for empname: kumar
old 1: insert into con values('&empid','&empname')
new 1: insert into con values('2','kumar')
insert into con values('2','kumar')
*
ERROR at line 1:
ORA-00001: unique constraint (SCOTT.SYS_C0010286) violated
5. ADDING CONSTRIANT:
Used to set any constraint to the specified column at the last by specifying the
constraint type and field name.
Syntax:
Create table tablename(Fieldname1 datatype(constraint)unique,fieldname2 datatype,
constraint constraintname constrainttype(fieldname));
Example:
SQL> create table con(empid varchar2(10),empname varchar2(10),constraint c1
primary key(empid));
Table created.
1 row created.
SQL> /
Enter value for empid: 1
Enter value for empname: vijay
old 1: insert into con values('&empid','&empname')
new 1: insert into con values('1','vijay')
insert into con values('1','vijay')
*
ERROR at line 1:
ORA-00001: unique constraint (SCOTT.C1) violated
6. ADD CONSTRAINT(ALTER)
Used to set the constraint for the table already created by using alter command.
Syntax:
Alter table tablename add constraint constraintname (fieldname)datatype,primary key.
Example:
SQL> create table con(empid varchar2(10),empname varchar2(10));
Table created.
Table altered.
7. DROP CONSTRAINT:
Used to drop the constraint.
Syntax:
Alter table tablename drop constraint constraintname.
Example:
SQL> alter table con drop constraint c1;
Table altered.
EMPID VARCHAR2(10)
EMPNAME VARCHAR2(10)
8. REFERENTIAL INTEGRITY:
Used to refer the primary key of the parent table from the childtable.
Syntax:
a)Create table tablename(Fieldname1 datatype primary key,fieldname2 datatype,
…………….Fieldname3 datatype);
b) Create table tablename(Fieldname1 datatype references,Parent
tablename(fieldname)
…………….Fieldname n datatype);
Example:
SQL> create table parent(eno varchar2(10),ename varchar2(10) primary key);
Table created.
1 row created.
SQL> /
Enter value for eno: 2
Enter value for ename: bala
old 1: insert into parent values('&eno','&ename')
new 1: insert into parent values('2','bala')
1 row created.
Table created.
1 row created.
SQL> /
Enter value for eno: 2
Enter value for ename: balaji
old 1: insert into child values('&eno','&ename')
new 1: insert into child values('2','balaji')
insert into child values('2','balaji')
*
ERROR at line 1:
ORA-02291: integrity constraint (SCOTT.SYS_C0010290) violated - parent key not
Found
9. ON DELETE CASCADE:
The changes done in parent table is reflected in the child table when references are
made .
Syntax:
Create table tablename(Fieldname1 datatype references,Parent tablename(fieldname),
On delete cascade);
Example:
1 row created.
Table created.
ENO ENAME
---------- ----------
2 a
SQL> delete from parent where eno=1;
1 row deleted.
SQL> select * from parent;
no rows selected
SQL> select * from child;
no rows selected
ii) SUBQUERY:
Syntax:
1. UNION:
Syntax:
Select <fieldlist> from <tablename1> where (condition) union select<fieldlist>
from<tablename2> where (condition);
2. INTERSECT:
Syntax:
Select <fieldlist> from <tablename1> where (condition) intersect select<fieldlist>
from<tablename2> where (condition);
3. IN:
Syntax:
Select <fieldlist> from <tablename1> where (condition) in select<fieldlist>
from<tablename2> where (condition);
4. BETWEEN:
Syntax:
Select <fieldlist> from <tablename1> where (condition) between select<fieldlist>
from<tablename2> where (condition);
5. LIKE:
Syntax:
Select <fieldlist> from <tablename> where <fieldname> like <expression>;
6. NOT LIKE:
Syntax:
Select <fieldlist> from <tablename> where <fieldname> not like <expression>;
7. ALL:
Syntax:
Select <fieldlist> from <tablename1>where <fieldname> all
Select <fieldlist> from <tablename2> where (condition);
8. ANY:
Syntax:
Select <fieldlist> from <tablename1> where (condition) any
Select <fieldlist> from <tablename2> where(condition);
Table created.
Table dropped.
Table created.
SQL> /
Enter value for empno: 2
Enter value for empname: bala
Enter value for empsalry: 20000
old 1: insert into employee values('&empno','&empname','&empsalry')
new 1: insert into employee values('2','bala','20000')
1 row created.
1 row created.
SQL> /
Enter value for empno: 3
Enter value for empname: chitra
Enter value for empsalry: 40000
old 1: insert into employee1 values('&empno','&empname','&empsalry')
new 1: insert into employee1 values('3','chitra','40000')
1 row created.
EMPNAME EMPNO
---------- ----------
bala 2
chitra 3
INTERSECT:
SQL> select empname,empno from employee where(empsalary>9000) intersect select
empname,empno from employee1 where(empsalary>9000);
EMPNAME EMPNO
---------- ----------
arun 1
IN:
SQL> select empname from employee where empsalary in(select empsalary from
employee1);
EMPNAME
----------
arun
SQL> select empno,empname from employee where empno in(select empsalary from
employee1);
no rows selected
SQL> select empno,empname from employee where empno in(select empno from
employee1);
EMPNO EMPNAME
---------- ----------
1 Arun
BETWEEN:
SQL> select empno,empname from employee where empsalary between 10000 and
30000;
EMPNO EMPNAME
---------- ----------
1 arun
2 bala
LIKE:
SQL> select empname,empno from employee where empname like 'b%';
EMPNAME EMPNO
---------- ----------
bala 2
NOT LIKE:
SQL> select empname,empno from employee where empname not like 'b%';
EMPNAME EMPNO
---------- ----------
arun 1
ALL:
SQL> select empname,empsalary from employee1 where empsalary > all (select
empsalary from employee where empsalary>10000);
EMPNAME EMPSALARY
---------- ----------
chitra 40000
ANY:
SQL> select empname,empsalary from employee1 where empsalary>any (select
min(empsalary) from employee);
EMPNAME EMPSALARY
---------- ----------
chitra 40000
iii) AGGREGATE FUNCTION:
1. COUNT:
Syntax:
Select count(field list) from table_name where condition;
2. SUM:
Syntax:
Select sum(field name) from table_name;
3. MINIMUM:
Syntax:
Select min(field name) from table_name;
4. MAXIMUM:
Syntax:
Select max(field name) from table_name;
5. AVERAGE:
Syntax:
Select avg(field name) from table_name;
1. ABSOLUTE:
Syntax:
Select abs(value) from dual;
2. MODULE:
Syntax:
Select mod(value1,value2) from dual;
3. POWER:
Syntax:
Select power(value1,value2) from dual;
4. SQUARE ROOT:
Syntax:
Select sqrt(value) from dual;
5. ROUND:
Syntax:
Select round(value) from dual;
v) ORDER BY AND GROUP BY CLAUSE :
1. ORDERBY CLAUSE:
Syntax:
select field name from table_name where condition order by field name asc/desc;
2. GROUPBY CLAUSE:
Syntax:
SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name;
3. HAVING CLAUSE:
Syntax:
SELECT column_name, aggregate_function(column_name)FROM table_name
WHERE column_name operator value GROUP BY column_name HAVING
aggregate_function(column_name) operator value;
COUNT:
COUNT (EMPNO)
------------
4
SUM:
SUM(EMPSALARY)
--------------
110000
MINIMUM:
MIN(EMPSALARY)
--------------
10000
MAXIMUM:
MAX(EMPSALARY)
--------------
50000
AVERAGE:
AVG(EMPSALARY)
--------------
27500
NUMBER FUNCTIONS:
ABS(-75.7)
----------
75.7
MOD(15,35)
----------
15
POWER(5,5)
----------
3125
SQL> select sqrt(64) from dual;
SQRT(64)
----------
8
ROUND(10.9)
-----------
11
CLAUSE :
ORDERBY CLAUSE :
ENO
----------
1
2
3
4
GROUPBY CLAUSE:
dept salary
---------------- --------------
Electrical 25000
Electronics 55000
Aeronautics 35000
InfoTech 30000
HAVING CLAUSE:
dept salary
------------- -------------
Electronics 55000
Aeronautics 35000
InfoTech 30000
RESULT:
Thus the simple and nested query commands were studied and practiced
successfully.
Ex. No. 2. B JOINS
AIM:
To execute the SQL statements with joins.
PROCEDURE:
Step 1: Start
Step 2: Create the table with its essential attributes.
Step 3: Insert attribute values into the table
Step 4: Execute different join commands and extract information from the table.
Step 5: Stop
1. EQUI JOIN:
It retrieves rows from two tables having a common column using ‘=’ operators.
Syntax:
Select <tablename1.fieldlist,tablename2.fieldlist> from <tablename1><tablename2>
where <tablename1.keyfield>=<tablename2.keyfield>;
2. INNER JOIN :
Inner join returns the matching rows from the tables that are being joined.
Syntax:
Select tablename1.fieldlist,tablename2.fieldlist from tablename1 inner join tablename2
on tablename1.keyfield = tablename2.keyfield;
3. OUTER JOIN :
Outer join returns the both matching and non-matching rows for the tables that are
being joined. An outer join is an extended form of the inner join. The rows in one table
having no matching rows in the other table will also appear in the result table with nulls.
OUTPUT / EXAMPLE(JOINS):
Table created.
1 row created.
SQL> /
Enter value for empid: 10ece02
Enter value for empname: bala
Enter value for deptid: ece
old 1: insert into employee values('&empid','&empname','&deptid')
new 1: insert into employee values('10ece02','bala','ece')
1 row created.
SQL> /
Enter value for empid: 10mech03
Enter value for empname: karthi
Enter value for deptid: MECH
old 1: insert into employee values('&empid','&empname','&deptid')
new 1: insert into employee values('10mech03','karthi','MECH')
1 row created.
Table created.
1 row created.
SQL> /
Enter value for deptid: ece
Enter value for deptname: electronics
old 1: insert into department values('&deptid','&deptname')
new 1: insert into department values('ece','electronics')
1 row created.
SQL> /
Enter value for deptid: mech
Enter value for deptname: mechanical
old 1: insert into department values('&deptid','&deptname')
new 1: insert into department values('mech','mechanical')
1 row created.
DEPTID DEPTNAME
---------- --------------------
ece electronics
cse computerscience
mech mechanical
EQUI JOIN:
SQL> select
employee.empid,employee.empname,department.deptid,department.deptname from
employee,department where employee.deptid = department.deptid;
EMPID EMPNAME DEPTID DEPTNAME
---------- ---------- ---------- --------------------
10ece02 bala ece electronics
10cse01 anand cse computerscience
INNER JOIN:
EMPID DEPTNAME
---------- --------------------
10ece02 electronics
10cse01 computerscience
EMPNAME DEPTNAME
---------- --------------------
anand computerscience
bala electronics
karthi
EMPNAME DEPTNAME
---------- --------------------
anand computerscience
bala electronics
karthi mechanical
RESULT:
AIM:
PROCEDURE:
Step 1: Create table with some attributes.
Step 2: Create view from single table with all attributes.
Step 3: Create view from single table with selected attributes.
Step 4: Create View from two tables with all attributes.
Step 5: Create View from two tables with selected attributes.
Step 6: Use DML commands in views.
Step 7: Drop the View.
COMMAND EXECUTION
1. Create a view from single table containing all columns from the base table.
View created.
3. Create view from two table containing all columns from the base table.
SQL> create view viiew2 as select * from emp1 full natural join emp2;
View created.
SQL> create view viiew3 as select ename, age, empid from emp1,emp2;
View created.
1. INSERT:
SQL> insert into viiew1 values('&eid','&ename','&salary');
Enter value for eid: 1
Enter value for ename: anu
Enter value for salary: 25000
old 1: insert into viiew1 values('&eid','&ename','&salary')
new 1: insert into viiew1 values('1','anu','25000')
1 row created.
SQL> /
Enter value for eid: 2
Enter value for ename: abi
Enter value for salary: 20000
old 1: insert into viiew1 values('&eid','&ename','&salary')
new 1: insert into viiew1 values('2','abi','20000')
1 row created.
SQL> /
Enter value for eid: 3
Enter value for ename: cibi
Enter value for salary: 37000
old 1: insert into viiew1 values('&eid','&ename','&salary')
new 1: insert into viiew1 values('3','cibi','37000')
1 row created.
SQL> /
Enter value for eid: 4
Enter value for ename: babu
Enter value for salary: 24000
old 1: insert into viiew1 values('&eid','&ename','&salary')
new 1: insert into viiew1 values('4','babu','24000')
1 row created.
SQL> /
Enter value for eid: 5
Enter value for ename: soman
Enter value for salary: 27000
old 1: insert into viiew1 values('&eid','&ename','&salary')
new 1: insert into viiew1 values('5','soman','27000')
1 row created.
SQL> /
Enter value for eid: 6
Enter value for ename: billu
Enter value for salary: 28000
old 1: insert into viiew1 values('&eid','&ename','&salary')
new 1: insert into viiew1 values('6','billu','28000')
1 row created.
1 anu 25000
2 abi 20000
3 cibi 37000
4 babu 24000
5 soman 27000
6 billu 28000
6 rows selected.
2. UPDATE:
1 row updated
1 anu 25000
8 abi 20000
3 cibi 37000
4 babu 24000
5 soman 27000
6 billu 28000
1 anu 25000
2 abi 20000
3 cibi 37000
4 babu 24000
6 billu 28000
3. DELETE
1 row deleted.
1 anu 25000
2 abi 20000
3 cibi 37000
4 babu 24000
6 billu 28000
5 rows selected.
DROP VIEW:
View dropped.
RESULT:
Thus the views were created and manipulated using insert, delete and update
commands.
Ex: No: 3. B SYNONYMS
AIM:
To write query for synonyms to minimize the impact of moving or renaming the
database objects.
PROCEDURE:
Step 1: Create the database which contains several tables using DDL and DML
command.
Step 2: Select particular table from the database provide permission using grand
command.
Step 3: Create temporary table name for that particular table.
Step 4: Display the table using select command.
EXPLANATION
A synonym is an alias for a database object. Synonyms may be used to reference
the original object in SQL as well as PL/SQL.
They can be used to hide ownership and location of the database objects they refer
to and minimize the impact of moving or renaming the database objects.
COMMAND EXECUTION
EXAMPLE
In your database you have a schema called pacet. This schema contains a table
called EMPLOYEES.
From now on, anyone can query your table using the synonym
SELECT * FROM EMPLOYEE_DATA;
RESULT:
Thus the synonyms were created using Data Control Language commands.
Ex: No: 3. C SEQUENCES
AIM:
To write query for sequence to database object from which multiple users may
generate unique integers.
PROCEDURE:
Step 1: Create the sequence using create sequence command.
Step 2: Delete the sequence using drop sequence command.
Step 3: Save the current point transaction using savepoint command.
Step 4: Perform undo operation using rollback command.
COMMAND EXECUTION
1. Create
Syntax:
CREATE SEQUENCE sequence_name
MINVALUE value
MAXVALUE value
START WITH value
INCREMENT BY value
CACHE value;
Example:
CREATE SEQUENCE employee
MINVALUE 1
MAXVALUE 888888888888888888888
START WITH 1
INCREMENT BY 1
CACHE 20;
2. Drop
Syntax :
DROP SEQUENCE sequence_name;
Example:
DROP SEQUENCE employee;
3. SAVEPOINT
Syntax:
SAVEPOINT identifier
RELEASE SAVEPOINT identifier
Example:
UPDATE employees
SET salary = 7000
WHERE last_name = 'SURESH';
SAVEPOINT sureshsave;
UPDATE employees
SET salary = 12000
WHERE last_name = 'SUNDAR';
SAVEPOINT sundarsave;
4. ROLLBACK
Syntax:
ROLLBACK [WORK] TO [SAVEPOINT] identifier
Example:
SELECT SUM (salary) FROM employees;
UPDATE employees
SET salary = 11000
WHERE last_name = 'SUNDAR';
COMMIT;
RESULT:
AIM
To write a Cursor Procedure to calculate Payroll process of an Employee.
PROCEDURE
Step 1: Start
Step 2: Initialize the Cursor Procedure based on the table attributes to which the actual
operation has to be carried out.
Step 3: Develop the procedure with the essential operational parameters.
Step 4: Specify the Individual operation to be each attribute.
Step 5: Execute the Cursor procedure.
Step 6: Stop
COMMAND EXECUTION
Table created.
1 row created.
1 row created.
1 row created.
Example:
SQL> declare
e_no number(6);
e_name varchar2(25);
net_salary number(8,2);
cursor cur_salary is select emp_no,
emp_name,basic+da_percent*basic/100+ma+other_allowance-deduction from sal;
begin
dbms_output.put_line('emp no '||' Name '||' Net salary');
dbms_output.put_line('--------------------');
open cur_salary;
loop
fetch cur_salary into e_no,e_name,net_salary;
exit when cur_salary%notfound;
dbms_output.put_line(rpad(e_no,10,' ')||rpad(e_name,25,' ')||net_salary);
end loop;
close cur_salary;
end;
/
OUTPUT:
emp no Name Net salary
1 vijay 7649.25
2 vasanth 5000
3 priya 2850
RESULT:
Thus the Cursor Procedure for calculating the Payroll process has been executed
successfully.
Ex: No: 5. A PROCEDURES
AIM:
PROCEDURE:
Step 1: Declare the necessary variables.
Step 2: Begin the program.
Step 3: Assign Values to the variables.
Step 4: Write the looping condition
Step 5: Perform calculation.
Step 6: End loop.
Step 7: Execute the procedure
1. Create
Syntax:
CREATE [OR REPLACE] PROCEDURE proc_name [list of parameters] IS
Declaration section
BEGIN
Execution section
EXCEPTION
Exception section
END;
Example:
SQL> create or replace procedure sum(n number) is
i number;
sum1 number;
begin
sum1:=0;
i:=0;
while i<=n
loop
sum1:=sum1+i;
i:=i+1;
end loop;
dbms_output.put_line(sum1);
end;
/
Procedure created.
Execution of procedure:
2. Drop:
Syntax:
Drop Procedure procedure_name;
Example:
Drop Procedure Sum;
RESULT:
Aim :
Procedure:
Step 1: Declare the necessary variables.
Step 2: Begin the program.
Step 3: Assign Values to the variables.
Step 4: Write the looping condition
Step 5: Perform calculation.
Step 6: End loop.
Step 7: Create the function
Step 8: Create the main procedure and call the function
Step 9:Execute the procedure.
COMMAND EXECUTION
Function created.
SQL> Declare
2 n number:=&n;
3 y number;
4 begin
5 y:=fnfact(n);
6 dbms_output.put_line(y);
7 end;
8 /
Enter value for n: 5
old 2: n number:=&n;
new 2: n number:=5;
120
COMMAND EXECUTION
Table created.
1 row created.
1 row created.
Function created.
SQL>declare
address varchar2(100);
begin
address:=findaddress(20312);
dbms_output.put_line(address);
end;
/
OUTPUT 1:
vijay,120/5D,bharathi street,NGO colony,629002
SQL> declare
2 address varchar2(100);
3 begin
4 address:=findaddress(23556);
5 dbms_output.put_line(address);
6 end;
7 /
OUTPUT2:
address not found
PL/SQL procedure successfully completed.
RESULT:
Thus the Function for searching process has been executed successfully
Ex. No: 6 TRIGGERS
AIM:
PROCEDURE:
Step 1: Start
Step 2: Initialize the trigger with specific table id.
Step 3:Specify the operations (update, delete, insert) for which the trigger has to be
executed.
Step 4: Execute the Trigger procedure for both Before and After sequences
Step 5: Carryout the operation on the table to check for Trigger execution.
Step 6: Stop
Database Triggers:
COMMAND EXECUTION
Syntax:
Create or replace trigger <Trigger_name> before/after insert/delete/update on
<Table_name> for each row/statement
DELCARE
<Declaration statements>
BEGIN
<Executable Statements>
END:
Example
SQL> create table emply101(eid varchar(20),ename char(25), age number(10), salary
number(10));
Table created.
1 row created.
SQL> /
Enter value for eid: e2
Enter value for ename: abi
Enter value for age: 24
Enter value for salary: 25700
old 1: insert into emply101 values('&eid','&ename','&age','&salary')
new 1: insert into emply101 values('e2','abi','24','25700')
1 row created.
SQL> /
Enter value for eid: e3
Enter value for ename: babu
Enter value for age: 30
Enter value for salary: 34000
old 1: insert into emply101 values('&eid','&ename','&age','&salary')
new 1: insert into emply101 values('e3','babu','30','34000')
1 row created.
SQL> /
Enter value for eid: e4
Enter value for ename: cibi
Enter value for age: 32
Enter value for salary: 32000
old 1: insert into emply101 values('&eid','&ename','&age','&salary')
new 1: insert into emply101 values('e4','cibi','32','32000')
1 row created.
SQL> /
Enter value for eid: e5
Enter value for ename: brindha
Enter value for age: 28
Enter value for salary: 31000
old 1: insert into emply101 values('&eid','&ename','&age','&salary')
new 1: insert into emply101 values('e5','brindha','28','31000')
1 row created.
Table created.
SQL> create or replace trigger tfg1 before insert on emply101 for each row
2 begin
3 insert into emply102 values(:new.eid,:new.ename,:new.age,:new.salary);
4 end;
5 /
Trigger created.
1 row created.
SQL> create or replace trigger trgrr15 after delete or update on emply101 for each row
2 begin
3 if deleting then
4 insert into emply102 values(:old.eid,:old.ename,:old.age,:old.salary);
5 elsif updating then
6 insert into emply102 values(:old.eid,:old.ename,:old.age,:old.salary);
7 end if;
8 end;
9 /
Trigger created.
7 rows selected.
1 row deleted.
1 row updated.
RESULT:
Thus the trigger for insert, delete and update are created.
Ex. No: 7 EXCEPTION HANDLING
AIM:
To perform exception handling for customer details.
PROCEDURE:
Step 1: start
Step 2: create the table with essential attributes.
Step 3: declare the user defined exception
Step 4: Raise the exception and handle it.
Step 5: Execute the result.
Step 6: stop
COMMAND EXECUTION
RESULT
RESULT:
AIM:
To create ER diagram for a software company with the following details,
1. Registered Students Details.
2. Courses Offered.
3. Students and their enrolled courses.
4. Registered Faculty Details.
5. Each student enrollment details like (Fee paid,Join date,Course Completion Date)
needs to be recorded.
6. Faculty and their handled courses during various durations.
Constraints:
One student can join in many courses .e.g A student can join in both c and cpp
courses.
A course should be taught by only one faculty during particular duration(start
date ,end date)
A faculty can teach many courses.
Few students may get discount on a course fee.
ER Diagram
Fees is associated enrollment as Same course can be offered at different fees for
different student.
Teach:SDate, EDate
B. DATABASE DESIGN USING NORMALIZATION
Problem
Consider any University Examination System, which consists of the enrolled students
result details. Suppose the university wants to maintain not only the results, but also
performance of the faculty, then it enhances the existing system by adding the details of
the Instructors.
Solution
To eliminate the anomalies like redundancy, insertion anomaly, updation anomaly and
deletion anomaly from any table, it should be decomposed into smaller relations using
Normalization techniques.
Introduction:
Basically normalization eliminates the duplicate data and makes insert, update and
delete operations much more efficient in terms of performance and space requirement
to store the data.
Hence we need to refine our design so that we make an efficient database in terms of
storage space and inserts, updates and deletes operations. The refining technique is
called as Normalization
In the above table, all the attributes are atomic, meaning they are not further
decomposable. So the above table satisfies the I NF.
Note - 1: A key attribute a candidate key, which can uniquely defines the other
attributes.
Note – 2: We can define functional dependency as,in a given relation R, X and Y are
attributes. Attribute Y is functionally dependent on attribute X if each value of X
determines EXACTLY ONE value of Y. This is represented as: X -> Y.
Note – 3: We can define partial functional dependency as, in a given relation R, X and Y
are attributes. Attribute Y is partially functionally dependent on attribute X only if it is
functionally dependent on sub-set of X.
To make this table 2NF, we have to remove all the partial dependencies.
Sname and DOB depends only on S#.
Cname, sem, Year and DOE depends only on C# Subject.
Marks and Grade depends only on S# Subject CC.
Fname depends only on FID CC.
Cname depends only on C#.
ColName depends only on CC.
In the above tables, No partial dependency exists between the key attributes and non-
key attributes. Hence the tables are in Second Normal Form (2 NF).
Third Normal Form (3 NF)
A relation R is said to be in the third normal form (3 NF) if and only if
it is in the second normal form.
no transitive dependency exists between non-key attributes and key attributes.
There is no transitive dependency in the above sub tables except Grade Table. The
GRADE is depends on MARKS and in turn MARKS depends on S# Subject CC. To bring
this table to third normal form we need to take off this Transitive Dependence. To
eliminate transitive dependency, we can decompose the RESULT table into MARKS and
GRADE.
Final Results:
Student (S#, Sname, DOB)
Corse (C#, Cname)
Sub_Date(C#, Subject, Semester, Year, DOE)
Faculty(FID, Fname, CC)
Marks(S#, Subject, CC, Marks)
Grade(lowaebound, upperbound, grade)
All the anomalies are removed and all dependencies are preserved.
RESULT:
Thus the database design usind ER diagram and normalization was performed for the
given problem.