3139 Database Management System Lab
3139 Database Management System Lab
E
Lab Manual
EG
for
LL
CO
IC
DATABASE MANAGEMENT
HN
SYSTEM LAB - 3139
EC
LYT
PO
3 rd Semester
DI
A'
M
INDEX
EX PAGE
LIST OF EXPERIMENTS
.NO NO
E
2 Implement Constraints 9
EG
LL
3 Implement Data Manipulation Language (DML) 14
CO
Implement Data Control Language (DCL)
4 commands 20
7 Views 32
YT
9 cursors 38
N
10 Triggers 39
DI
11 Database Connectivity 42
A'
M
EXPERIMENT NO: 1
OBJECTIVES
E
EG
THEORY
LL
● CREATE - It is used to create a table.
CO
● ALTER – The structure of a table can be modified by using the ALTER
TABLE command. This command is used to add a new column, modify the
existing IC
column definition and to include or drop integrity constraint.
HN
● DROP - It will delete the table structure provided the table should be empty.
EC
PROCEDURE
N
CREATION OF TABLE:
DI
SYNTAX:
A'
EXAMPLE:
ALTER TABLE
Syntax:
EXAMPLE:
E
EG
(b)To Add Multiple columns to existing Table
LL
Syntax:
CO
alter table table-name add(column-name1 datatype1, column-name2
datatype2, column-name3 datatype3);
EXAMPLE: IC
HN
alter table Employee add(salary number(7), age(5));
EC
Syntax:
L
EXAMPLE:
N
Syntax:
M
Syntax:
E
alter table Employee rename address to Location;
EG
LL
RENAMING TABLES
CO
Syntax:
EXAMPLE:
IC
HN
rename Employee to Employee 1;
TRUNCATE TABLE
EC
.
Syntax:
YT
Example:
DESTROYING TABLES
A'
Syntax:
M
Example:
DESCRIBE TABLES
. Syntax:
Example:
desc employee;
E
RESULT:
EG
The DDL commands have been executed successfully
LL
Problems
CO
1. Create the tables described below
Description
IC
: used to store product information
HN
Column name Data type size
EC
PRODUCTNO Varchar2 6
YT
DESCRIPTION Varchar2 15
UNITMEASURE Varchar2 10
QTYONHAND Number 8
N
DI
REORDERLVL Number 8
CLIENTNO Varchar2 6
NAME Varchar2 20
ADDRESS1 Varchar2 30
ADDRESS2 Varchar2 30
E
CITY Varchar2 15
EG
PINCODE Number 8
LL
STATE Varchar2 15
CO
BALDUE Number 10,2
SALESMANNO Varchar2 6
SALESMANNAME Varchar2 20
L
PO
ADDRESS1 Varchar2 30
ADDRESS2 Varchar2 30
N
DI
CITY Varchar2 15
PINCODE Number 8
A'
M
STATE Varchar2 15
SNO Number 5
SNAME Varchar2 20
AGE Number 5
E
SDOB Date
EG
SMARK1 Number 4,2
LL
SMARK2 Number 4,2
CO
SMARK3 Number 4,4
IC
HN
EC
EXPERIMENT NO:2
CONSTRAINTS
AIM:
THEORY
E
Constraints are the business Rules which are enforced on the data being stored
EG
in a table are called Constraints
LL
TYPES OF CONSTRAINTS:
1) Primary key
CO
2) Foreign key/references
3) Check
4) Unique
5) Not null
6) Null
IC
HN
7) Default
PROCEDURE
EC
Syntax:
columnname3 DATATYPE,..... );
A'
EXAMPLE
M
Syntax:
EXAMPLE
E
(b) CHECK CONSTRAINT
EG
The CHECK Constraint defined at column level
LL
Syntax:
CO
CREATE TABLE tablename
(Columnname1 DATATYPE CHECK (logical expression), columnname2
IC
DATATYPE, columnname3 DATATYPE,...);
HN
EXAMPLE
EC
number(2));
L
Syntax:
N
EXAMPLE
M
Syntax
EXAMPLE
E
design varchar2(15),sal number(5), UNIQUE(design));
EG
LL
The UNIQUE Constraint defined at the the table level
CO
Syntax
Syntax
EXAMPLE
A'
Problems
E
must start with
EG
„p‟
LL
PROFITPERCENT Varchar2 4,2 Not Null
CO
UNITMEASURE Varchar2 10 Not Null
Null,cannot be
0
YT
Null,cannot be
PO
0
N
ADDRESS1 Varchar2 30
ADDRESS2 Varchar2 30
CITY Varchar2 15
PINCODE Number 8
STATE Varchar2 15
E
BALDUE Number 10,2
EG
LL
Table Name : SALESMAN_MASTER
CO
Description : used to store salesman information working for the company
SALESMANNO Varchar2
IC 6 Primary
HN
key/first letter
must start with
EC
„S‟
YT
ADDRESS2 Varchar2 30
CITY Varchar2 15
N
DI
PINCODE Number 8
STATE Varchar2 15
A'
M
EXPERIMENT NO 3
DATA MANIPULATION LANGUAGE
AIM:
OBJECTIVES
E
THEORY
EG
DML commands are the most frequently used SQL commands and is used to
LL
query and manipulate the existing database objects. Some of the commands are
1. INSERT
CO
This is used to add one or more rows to a table. The values are separated
by commas and the data types char and date are enclosed in apostrophes.
The values must be entered in the same order as they are defined.
2. SELECT IC
It is used to retrieve information from the table.it is generally referred to
HN
as querying the table. We can either display all columns in a table or only
specify column from the table.
EC
3. UPDATE
It is used to alter the column values in a table. A single column may be
updated or more than one column could be updated.
YT
4. DELETE
After inserting row in a table we can also delete them if required. The
L
clause
N
PROCEDURE
DI
INSERT COMMAND
A'
Syntax:
Example:
(b) Inserting more than one record using a single insert commands:
Syntax:
Example:
E
( c) Skipping the fields while inserting:
EG
Insert into <tablename>(<column name1>,<column name3>)>values
LL
(<expression1>,<expression3>);
Other way is to give null while passing the values.
CO
SELECT COMMAND IC
HN
(a) view all rows and all columns
Syntax:
EC
Example:
L
Syntax:
N
DI
Example:
A'
Syntax:
SELECt <column1>, <column2> FROM <tablename> WHERE <condition> ;
Example:
Syntax:
SELECT DISTINCT <column1>, <column2> FROM <tablename>
Example:
E
EG
UPDATE COMMAND
LL
(b)updating all rows
CO
Syntax:
update tablename set IC
columnname1>=<exprssion1>,<columnname2>=<exprssion2>;
HN
Example:
EC
Syntax:
N
Example:
A'
DELETE COMMAND
(b)Removal of all rows
Syntax:
E
EG
Delete from <table name> where <condition>;
Example:
LL
delete from emp where empno=135;
CO
RESULT
IC
The DML commands are executed successfully.
HN
EC
Problems
YT
E
P00324 Skirts 4 piece 120 750 500
EG
P02345 CottonJe 3 piece 80 850 550
LL
ans
CO
2. Data for PRODUCT_MASTER table
IC
HN
Sales Name Address1 Address2 city Pincode State
manN
EC
o
YT
4
3. Data for SALESMAN_MASTER table
E
EG
f. Find the names of salesmen who have a salary equal to Rs.3000
LL
5. Exercise on updating the records on a table
CO
a. Change the city of ClientNo‟C00005‟ to „Bangaluru‟.
b. Change the cBalDue of ClientNo‟C00001‟ to Rs.1000.
IC
c. Change the costprice of „Shirt „ to Rs.450.
HN
d. Change the city of salesman to Pune.
EC
c. Delete from the Client_master where the column state holds the
DI
value „Tamilnadu‟.
A'
M
EXPERIMENT NO:3
DATA CONTROL LANGUAGE
AIM:
OBJECTIVES
E
EG
THEORY:
LL
Data Control Language (DCL) consists of various commands which are related
CO
to data sharing and security of data in database.
They are
GRANT
REVOKE
IC
HN
Granting Privileges:
EC
Objects that are created by a user are owned and controlled by that user. If user
wishes to access any of the objects belonging to another user, the owner of the
YT
object will have to give permissions for such access. This is called Granting of
L
Privileges.
PO
Syntax:
A'
ON object name
TO username;
Object Privileges:
each object privilege that is granted authorizes the grantee to perform some
operation on the object. The user can grant all the privileges or grant only
specific object privileges.
The list of object privileges is as follows:
• ALTER: allows the grantee to change the table definitions with the ALTER
table command.
• DELETE: allows the grantee to remove the records from the table with the
E
DELETE command.
EG
• INDEX: allows the grantee to create an index on the table with the CREATE
LL
INDEX command.
• INSERT: allows the grantee to add records to the table with the INSERT
CO
command.
• SELECT: allows the grantee to query the table with SELECT command.
IC
• UPDATE: allows the grantee to modify the records in the table with the
HN
UPDATE command.
Revoking privileges given:
EC
Privileges once given can be denied to a user using the REVOKE command.
YT
The object owner can revoke privileges granted to another user. A user of an
object who is not owner, but has been granted the GRANT privilege, has the
L
PO
Syntax:
A'
ON object name
FROM username;
The REVOKE command is used to revoke object privileges that the user
previously granted to the Revoke.
E
EG
LL
CO
IC
HN
EC
L YT
PO
N
DI
A'
M
EXPERIMENT NO:5
COMPUTATIONS ON TABLE DATA WITH
BUILT IN FUCTIONS
AIM:
OBJECTIVES
E
functions
EG
THEORY
Group Functions/Aggregate functions
LL
A group function returns a result based on group of rows.
CO
1. avg
Example: select avg (total) from student;
2.max
IC
Example: select max (percentagel) from student;
HN
2.min
Example: select min (marksl) from student;
4. sum
EC
Special Clauses:
Group by clause
This allows us to use simultaneous column name and group functions.
Having clause
This is used to specify conditions on rows retrieved by using group by
clause.
Example: Select max(percentage), deptname from student group by
E
deptname having count(*)>=50;
EG
In / not in – used to select a equi from a specific set of values
Any - used to compare with a specific set of values
LL
Between / not between – used to find between the ranges
CO
Like / not like – used to do the pattern matching
PROCEDURE
IC
HN
OUTPUT
RESULT
EC
YT
PROGRAMS
L
table data.
N
a.list the names of all clients having „a‟ as the second letter in their
DI
names.
A'
f.list products whose selling price is greater than 500 and less than or
equal to 750
g.listing of names,city and state of clients who are not in the state of
„maharashtra‟.
h.count the total number of orders
i.calculating the average price of all products.
E
j.determining the maximum and minimum price for the product
EG
prices.
LL
k.count the number of products having the price greater than or equal
to 500
CO
2. SQL statements for using having and group by clauses.
IC
a. printing the description and total quantity sold for each product.
HN
b. Finding the value of each product sold
c. find out the total of all the billed orders for the month of june.
EC
L YT
PO
N
DI
A'
M
EXPERIMENT NO:6
NESTED QUERIES/SUB QUERIES AND JOINS
AIM:
OBJECTIVES
E
To understand nested queries and joins.
EG
THEORY
LL
a) NESTED QUERIES:
CO
A sub query is a query within a query. In Oracle, we can create sub queries
within your SQL statements. These sub queries can reside in the WHERE
IC
clause, the FROM clause, or the SELECT clause.
HN
b) JOINS:
Natural join:
YT
It returns the matching rows from the table that are being joined
.
L
Syntax:
PO
Syntax:
>select <attribute> from TN1 innerjoin TN2 on TN1.attribute=TN2.attribute.
A'
Syntax:
5. select <attribute> from TN1 left outer join TN2 on
TN1.attribute=TN2.attribute.
2. select <attribute> from TN where TN1.attribute(+)=TN2.attribute.
Syntax:
4. select <attribute> from TN1 right outer join TN2 on
TN1.attribute=TN2.attribute.
2. select <attribute> from TN where TN1.attribute=(+)TN2.attribute.
Full join:
E
>select <attribute> from TN1 full join TN2 on TN1.attribute=TN2.attribute.
EG
PROCEDURE
LL
CO
NESTED QUERIES -
ADDRESS VARCHAR2(30)
BASIC_SAL NUMBER(12,2)
YT
JOB_STATUS VARCHAR2(15)
DNO NUMBER(3)
L
PO
NO_OF_STAFF NUMBER(3)
M
PJOB CHAR(12)
E
2 Mahendran RainbowColon 5000 Supervisor 10
EG
y
3 RajKumar EastCoastRoad 10000 Professor 2
4 Shirley KKnagar 8000 AsstManager 3
LL
CO
SQL> select * from Pro_det;
IC
HN
PNO PNAME NO_OF_STAFF
1 DBMS 2
EC
2 COMPILER 3
3 C1 1
YT
1 1 Programmer
2 1 Analyst
DI
1 2 Analyst
A'
2 2 Programmer
M
NESTED QUERIES
(i) SQL> select ename from emp_det where dno not in(select dno from
emp_det where ename ='SaravanaKumar');
ENAME
---------------
RajKumar
Shirley
(ii)SQL> select ename, dno from emp_det where dno = (select dno from
emp_det where ename ='RajKumar');
ENAME DNO
--------------- ----------
RajKumar 2
E
(iii)SQL> select ename from emp_det where eno in(select eno from work_in
EG
where pno = (select pno from pro_det where pname = 'DBMS')) order by
ename;
LL
ENAME
---------------
CO
Mahendran
SaravanaKumar
(iv)SQL> select ename, basic_sal from emp_det where dno = 2 and
IC
basic_sal>(select max(basic_sal) from emp_det where dno = 10) order by
ename;
HN
ENAME BASIC_SAL
EC
--------------- ----------
RajKumar 10000
YT
(v)SQL> select pno,pname from pro_det where exists(select pno from work_in
where work_in.pno =pro_det.pno);
L
PO
PNO PNAME
------ ------------------------------
N
1 DBMS
2 COMPILER
DI
='RajKumar');
MAX(BASIC_SAL)
---------------
E
8000
EG
(ix)SQL> select * from emp_det where basic_sal < (select avg(basic_sal) from
LL
emp_det);
CO
ENO ENAME ADDRESS BASIC_SAL JOB_STATUS DNO
---- --------------- --------------- ---------- --------------- ----------
2 Mahendran RainbowColony 5000 Supervisor 10
JOINS
IC
HN
SQL> create table emp(name varchar2(20),salary number(10));
Table created.
EC
ashu 10000
asma 1200
L
asif 2000
PO
arif 1000
niyas 3000
SQL> create table emp1(name varchar2(20),empid number(10));
N
Table created.
DI
.
SQL> select * from emp1;
A'
NAME EMPID
M
-------------------- ----------
fathi 12
sumi 32
priya 11
wahab 10
sweety 9
asma 1200
6 rows selected.
NATURAL JOIN
************
SQL>select emp.name,salary from emp,emp1 where emp.name=emp1.name
NAME SALARY
-------------------- ----------
asma 1200
LEFT OUTER JOIN
SQL>select emp.name,salary from emp left outer join emp1 on
emp.name=emp1.name
NAME SALARY
E
-------------------- ----------
EG
asma 1200
asif 2000
LL
arif 1000
niyas 3000
CO
ashu 10000
RIGHT OUTER JOIN
IC
SQL>select emp1.name,empid from emp right outer join emp1 on
emp.name=emp1.name
HN
NAME EMPID
-------------------- ----------
asma 1200
EC
sweety 9
sumi 32
YT
wahab 10
fathi 12
L
priya 11
PO
6 rows selected.
FULL JOIN
SQL>select emp1.name,emp.name,emp1.empid,salary from emp full join emp1
N
on
DI
emp.name=emp1.name
NAME NAME EMPID SALARY
A'
asif 2000
arif 1000
niyas 3000
ashu 10000
sweety 9
sumi 32
wahab 10
fathi 12
priya 11
10 rows selected.
RESULT:
Thus the nested queries and join operations are executed and verifiedin DBMS.
E
Programs
EG
1. Exercises on sub-queries
LL
a) find the non moving products.ie products not being sold.
CO
b) Find the name and complete address for the customer who has placed order
number „o19001‟
IC
c) find the clients who have placed orders before the month of may „02
HN
d) find the names of clients who have placed orders worth Rs.10000 or more.
EC
L YT
PO
N
DI
A'
M
EXPERIMENT NO:7
VIEWS
AIM:
OBJECTIVES
To implement views
E
EG
THEORY
LL
A view is the tailored presentation of data contained in one or more table and
can also be said as restricted view to the data‟s in the tables. A view is a “virtual
CO
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 as base table . A view is a
logical table based on a table or another view. A view contains no data of its
IC
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
HN
stored as a SELECT statement in the data dictionary .
Advantages of a view:
EC
Syntax:
SELECT column_name(s)
DI
FROM table_name
WHERE condition
A'
M
Example
Create or replace view empview as select * from emp;
PROCEDURE
1) create a table aa
E
Bb 23 2001 12 23435
EG
Cc 55 342 76 687478
dd 2 1233 123 53616578
LL
ee 21 1111 111 12435798
CO
3) create table qq
SQL> create table qq(name varchar2(20),book number(10),author
IC
varchar(20),publisher varchar2(20),ISBN number(20));
HN
4) describe table qq
EC
bb 21 23 dfd 573568
cc 43 55 fg 65839
L
ee 44 21 dfd 1235798
PO
oo 87 34 gfh 6358379
5) create a view on qq
N
DI
View created.
M
21 bb dfd
E
SQL> create view wq as select name,ISBN,publisher from qq where book>21
EG
View created.
SQL> select * from wq;
LL
NAME ISBN PUBLISHER
CO
-------------------- ---------- --------------------
cc 65839 fg
ee 1235798 dfd
oo 6358379 gfh IC
HN
SQL> create view ss as select name,book from aa union select name,book from
qq;
EC
View created.
SQL> select * from ss;
NAME BOOK
YT
-------------------- ----------
bb 21
L
bb 23
PO
cc 43
cc 55
dd 2
N
ee 21
DI
ee 44
oo 87
A'
8 rows selected.
M
Result
Thus the view creation commands are executed successfully
Problems
Table:Hosp_doc
Doc_code Varchar2(4)
Doc_name Varchar2(4)
E
Specialization Varchar2(4)
EG
Department Varchar2(4)
LL
Date_of_join Date
CO
Exper Number(2)
IC
1) create a view vw_doctor on Hosp_doc table
HN
2) create another view that contains doctor codes and doctor names of
„orthology‟ department
EC
EXPERIMENT NO:8
FUNCTIONS AND PROCEDURE
AIM:
To find factorial of a number using function
OBJECTIVES
E
To write PL/SQL(Functions)and to understand stored procedures in SQL.
EG
THEORY
LL
FUNCTION:
CO
A function is a subprogram that computes a value.
syntax
IC
Create or replace function<function_name>[argument]
Return datatype is
HN
(local declaration)
begin
EC
(executable statements)
[Exception]
(exception handlers)
YT
End
L
PROCEDURE:
PO
[(parameter)]
DI
is/as
declaration
A'
begin
M
pl/sql codes
[exception]
end
PROGRAM
E
i:=i+1;
EG
end loop;
return f;
LL
end fact; /Function created.
SQL>begin
CO
2 dbms_output.put_line('the factorial='||fact(&a));
3* end;
OUTPUT IC
HN
SQL> /
Enter value for a: 4
old 2: dbms_output.put_line('the factorial='||fact(&a))
EC
RESULT:
PO
Problems;
1) procedure to find whether a given number is odd or even
A'
EXPERIMENT NO: 9
CURSOR
AIM
To retrieve all students who have registered for Diploma and store their details
into another table called diploma (id,name) using cursors.
E
EG
OBJECTIVES
LL
To implement cursor
CO
PROCEDURE
1) TABLE CREATION
IC
SQL>create table student(id number,name varchar2(25),programme
varchar2(25));
HN
SQL>create table diploma(id number,name varchar2(25));
EC
Id name programme
A'
1 rohan diploma
M
2 anu MA
3 robert diploma
4 tom btech
5 sunny diploma
SQL>declare
2 cursor stud is select * from students where programme =”diploma‟;
3 id students.id%type;
4 name students.name%type
5 prog students.programme%type
6 begin
7 open stud;
8 loop
9 fetch stud into id,name,prog;
10 exit when stud%notfound;
11 insert into diploma values(id,name);
12 endloop;
E
13 end;
EG
14 /
LL
OUTPUT
CO
RESULT
PROGRAMS IC
1.A HRD manager has decided to raise the salary of all employees in
HN
department number 20 by 0.05.Whenever such raise is given to the
employees,the employee number ,the date when raise was given and raise
amunt are maintained in the emp_raise table.Write a PL/SQL block using
EC
cursors to update the salary of each employee of dept no 20 and insert a record
in the emp_raise table as well
L YT
PO
N
DI
A'
M
EXPERIMENT NO: 10
TRIGGER
AIM
Create a Trigger for EMP table it will update another table SALARY while inserting
values
OBJECTIVES
To develop and execute a Trigger for Before and After update/Delete/Insert
E
operations on a table
EG
THEORY.
LL
PROCEDURE
CO
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. IC
step 4: execute the trigger procedure for both before and after sequences
HN
step 5: carryout the operation on the table to check for trigger execution.
step 6: stop
EC
PROGRAM
sql> create table emp(iname varchar2(10),iid number(5),salary number(10));
YT
table created.
L
PO
table created.
DI
a varchar2(10);
begin
a:=:new.iname;
update sal set
totalsal=totalsal+:new.salary,totalemp=totalemp+1 where
iname=a;
end;
/
trigger created.
E
1 row created.
EG
sql> select * from sal;
iname totalemp totalsal
LL
---------- ---------- ----------
CO
vec 1 1000
srm 0 0
srm 1 3000
sql> insert into emp values('vec',100,5000);
L
1 row created.
PO
vec 2 6000
srm 1 3000
A'
1 row created.
RESULT:
The trigger procedure has been executed successfully for both before and after
E
sequences.
EG
Problems
LL
1. Write a trigger that stores the details of students changing their program from
CO
CT to CHM.
2. Write an update trigger on CLIENT_MASTER table.The system should keep
track of the records that are being updated.The old values of the updated record
olddate date
L
PO
N
DI
A'
M
Experiment No:11
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.
E
Objective:
EG
To study the concept of various levels of normalization and understand how to
convert into normalized forms.
LL
Requirements: Mysql database software
CO
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
IC
to the rules and regulations of each normal forms.
Procedure:
HN
Consider a student table as given below
Social Security Number FirstName LastName Major
EC
Information
Science
L
PO
We can easily verify that this table satisfies the definition of 1NF: viz., it has no
duplicated rows; each cell is single-valued (i.e., there are no repeating groups or
arrays); and all the entries in a given column are of the same kind. In this table
we can see that the key, SSN, functionally determines the other attributes;
i.e.,FirstName, LastName, and Major. .
Experiment No:12
Objective:
E
EG
To study the concept of various levels of normalization and understand how to
convert into normalized forms.
LL
Requirements: Mysql database software
CO
Design/Theory
Create a database table in SQL with a few no of rows and
IC
columns.Analyze the table and determine to which normal form it beongs to
according to the rules and regulations of each normal forms.
HN
Procedure:
Consider a book database table as given below.
EC
Name Name
L
Yudof Mark Child Abuse and Legal Law Library Townes Hall
Neglect Procedure
DI
s
A'
y Library
Graves Robert The Golden Fleece Greek Classics Library Waggener Hall
Literature
Miksa Francis Charles Ammi Cutter Library Library and Perry-
E
By examining the table, we can infer that books dealing with history,
EG
cognitive psychology, and folksong are assigned to the PCL General Stacks
collection; that books dealing with legal procedures are assigned to the Law
LL
Library; that books dealing with Greek literature are assigned to the Classics
Library; that books dealing with library biography are assigned to the Library
CO
and Information Science Collection (LISC);and that books dealing with music
literature are assigned to the Fine Arts Library.
IC
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
HN
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
EC
Building.
YT
Thus we can see that a transitive dependency exists in the above table :
any book that deals with history, cognitive psychology, or library biography
L
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,
N
we also know not only what library or collection it will be assigned to but also
what building it is physically housed in.
DI
information: from three different rows we can see that the PCL General Stacks
M
are in the PCL building. For another thing, we have possible deletion anomalies:
if the Yudof book were lost and its row removed from 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
To solve this problem decompose the above table into three different tables as
follows
Table A
E
Last First
EG
Name Name
LL
Berdahl Robert The Politics of the Prussian
Nobility
CO
Yudof Mark Child Abuse and Neglect
Collecting
N
Table B
M
E
Collecting
EG
English and Scottish Ballads Folksong
LL
Table C
CO
Subject Collection or Library
History
IC
PCL General Stacks
HN
Legal Procedures Law Library
EC
Collection
Music Literature Fine Arts Library
N
DI
Table D
Collection or Library Building
E
EG
LL
CO
IC
HN
EC
L YT
PO
N
DI
A'
M
Experiment No: 13
Database Connectivity
Java Database Connectivity
Aim: To understand the java database connevtivity
Problem Statement:
A program which connects to an online book database table and select the tuple
and display it.
E
Objective:
EG
To understand the connectivity to a database table using java. In java database is
LL
accessed through java database connectivity(JDBC).
CO
Requirements: Mysql database software, Java software.
Design/Theory:
IC
The four main components required for implementation of JDBC are
application,driver manager, data source specific drivers and corresponding data
HN
sources. The application program establishes/terminates connection with data.
Driver manager will load JDBC drivers and pass JDBC function calls from the
EC
application to the driver.The data source processes commands from the driver
and return the results.
1. Drivers for the database are loaded by using Class.for Name.
YT
name(db.onlinebook.edu)
PO
{
String URL =”jdbc:oracle:oci8:@db.onlinebook.edu:100:onbook_db”;
DI
Class.forName(“oracle.jdbc.driver.OracleDriver”);
Connection cn=DriverManager.getConnection(URL,U_id, Pword);
A'
Statement st = Cn.createStatement();
M
try
{
st.executeUpdate(“INSERT INTO AUTHOR
VALUES('A010','SMITH',JONES','TEXAS')”);
}
catch(SQLException se)
{
E
EG
LL
CO
IC
HN
EC
L YT
PO
N
DI
A'
M
}
ResultSet rs = st.execute Query(“SELECT Aname,State from AUTHOR
WHERE City = 'Seatle'”);
while(rs.next())
{
System.out.println(rs.getString(1) + “ “+rs.getString(2));
}
st.close();
Cn.close();
}
E
EG
LL
CO
IC
HN
EC
LYT
PO
N
DI
A'
M
Experiment No:14
Database Connectivity
AIM:
To create a PHP-Mysql Program to enter data into Mysql
Problem Statement:
A php program that connects to a database table and insert values into the table.
Objective:
E
EG
To understand the connectivity to a database table using php and how to insert
new values into that table.
LL
Requirements:
CO
Mysql database software, LAMP Server and Html
Design/Theory: IC
HN
In an existing or a newly created database an employee table is formed with
attributes firstname, lastname and email. A php-html program is used to insert
EC
E
echo "ERROR";
EG
}
?>
LL
<?php
// close connection
CO
mysql_close();
?>
<html>
<body> IC
HN
<form action= "<?php $_php_self ?>" method = "GET">
Empid: Empname: Empage: Dept: City
EC
</form>
</body></html>
A'
M
EXPERIMENT NO: 15
DATABASE CONNECTIVITY
AIM
Create a php program that allows to enter the employee details into a database.
To create an application program that process a query which returns the grade
result of a student after processing the marks table.
E
OBJECTIVES
EG
To understand PHP mysql database connectivity.
LL
To study the concept of connecting database using an application program
(PHP) and process results after manipulating the database table
CO
Requirements:
IC
Mysql database software, LAMP Server and html.
HN
PROCEDURE
Create a database in Mysql. Create a 'marks' table with fields regno, name,
EC
batch, mark1, mark2 and mark3. Write a function which finds the total marks
and if the total marks is greater than 225 then the result is categorized as
YT
“Distinction”, if the total marks is less than 225 , the result is “firstclass”, it the
total marks is less than 180, the result is “second class”, if the total marks is less
L
than 150 the result is “passed”. If the marks in any one of the subject is less than
PO
php code:
<?php
$user_name = "root";
$password = "";
$server = "localhost";
$database = "mysql";
$regno = $_POST['regno'];
E
//$regno = 1;
EG
$db_handle = mysql_connect($server, $user_name, $password);
LL
if (!$db_handle)
CO
{
die('Could not connect: ' . mysql_error());
}
IC
HN
//echo 'Connected successfully';
$db_found = mysql_select_db($database);
EC
if ($db_found)
YT
{
L
$record = mysql_fetch_array($result_set);
echo "<BR>MARKLIST";
A'
echo "<BR>Mark3...:".$record['mark3'];
echo "<BR>Result..:".
compute_result($record['mark1'],$record['mark2'],$record['mark3']);
}
else
{
E
echo "<BR>Database not Found";
EG
}
LL
mysql_close($db_handle);
CO
function compute_result($m1, $m2, $m3)
{
$tmarks = $m1 + $m2 + $m3; IC
HN
if (($m1<40) || ($m2<40) || ($m3<40))
$result = "Failed";
EC
$result = "Passed";
elseif ($tmarks<180)
L
PO
else
A'
$result = "Distinction";
M
return $result;
}
?>
Html code:
<html>
<body>
<FORM Method = "post" Action="connect1.php">
Reg No:
E
<INPUT Type = "text" name = "regno"> <BR>
EG
<INPUT type = "submit" value = "Show Result">
LL
</FORM>
CO
</body>
</html>
OUTPUT IC
HN
RESULT
EC
L YT
PO
N
DI
A'
M
1. What is a database?
2. What is DBMS?
3. Give an example for an RDBMS.
4. List the benefits of DBMS.
5. Disadvantage in File Processing System
6. What is a key? what are different keys in database?
7. What is a primary key?
8. What is a secondary key?
9. What is a candidate key?
10. What is an alternate key?
E
11. What is a super key?
EG
12. What is a composite key?
13. What is a relation?
14. What is a table?
LL
15. What is an attribute?
16. What is a domain?
CO
17. What is a tuple?
18. What is a selection?
19. what is a join operation?
IC
20. What are base operations in relational algebra?
21. What are different DBMS facilities? How many types of facilities are provided by a
HN
DBMS?
22. What is Data Definition Language?
23. What is Data Dictionary?
EC
E
59. What is Relational Calculus?
EG
LL
CO
IC
HN
EC
L YT
PO
N
DI
A'
M