Вы находитесь на странице: 1из 6


A Database to manage the insurance of a Vehicle

Person (driverid, name, address)

Car (Regno, model, year)
Accident (Report-no,date, location)
Owns (driverid,regno)
Participated (driverid, Regno, reportno, damageamount)

Creation of tables:

create table person26(driverid number not null,name varchar2(20),address varchar2(20),

primary key(driverid));

create table car26(regno number not null,model varchar2(20),year number(10),

primary key (regno));

create table accident26(repno number(10) not null, adate date,location varchar2(20),

primary key(repno));

create table owns26(drivid number(10),regdno number(10),

foreign key(drivid) references person26(driverid),
foreign key(regdno) references car26(regno));

create table participated26(driverid number(10),regno number(10),repno number(10),

damagamt number(10),
foreign key(driverid) references person26(driverid),
foreign key(regno) references car26(regno),
foreign key(repno) references accident26(repno));



1.Write a query to display name of a person and the car he/she owns?
Select p.name,c.model
from person26 p,car26 c,owns26 o
where p.driverid=o.drivid and c.regno=o.regdno;

2.Write a query to check a person with a specific id has met with an accident in the year
select p.driverid from person26 p,participated26 p1,accident26 a where
p.driverid=p1.driverid and a.repno=p1.repno and a.adate like '%03';
3.A query to find the total number of people with who won the cars that were involved in
the accident in the year 2002.
select count(*) from person26 p,participated26 p1,accident26 a,owns26 o where
p.driverid=o.drivid and a.repno=p1.repno and a.adate like '%02';

4.Find the no. of accidents in which cars belonging to specific model where involved.
Select c.model,count(c.model) from accident26 a,participated26 p,car26 c where
a.repno=p.repno and c.regno=p.regno group by c.model;

Database of an Employee:

Departmentlocation(deptnum, deptloc)
Project(pname, pno, ploc,deptnum)
Dependent(eno, dependentname,dob,relationship)

Creation of tables:

create table employ26

(fname varchar2(15) not null,
mname varchar2(10),
lname varchar2(15),
eno number(10),
dob date,
address varchar2(20),
sal decimal(10,2),
supno number(10),
dno number(10) not null,
primary key(eno),
foreign key(dno)references department26(deptnum));

create table department26

(deptname varchar2(20) not null,
deptnum number(10) not null,
mgreno number(10) not null,
mgrstdate date,
primary key(deptnum),unique(deptname));

create table departlocs26(deptnum number(10) not null,deptloc varchar(10) not null,

primary key(deptnum,deptloc),
foreign key(deptnum)references department26(deptnum));
create table project26
(pname varchar2(20),
pno number(10) not null,
ploc varchar2(20),
deptnum number(10),
primary key(pno),
foreign key(deptnum) references department26(deptnum));

create table workson26

(enum number(10) not null,
pnum number(10) not null,
hours decimal(3,1) not null,
primary key(enum,pnum),
foreign key(enum) references employ26(eno),
foreign key(pnum) references project26(pno));

create table dependent26

(enum number(10) not null,
deptname varchar2(20) not null,
dob date,
relationship varchar(10),
primary key(enum,deptname),
foreign key(enum) references employ26(eno));


Retrieve the names of employees in the deptartment5 who works for more than 10 hrs for
the project name.
Select fname from employ26 where eno in (select eno from workson26 where pno
in(select pno from project26 where hours>10 and deptno=5));

Find the names of employees who are directly supervised by ---

Select fname from employ26 where supno in (select eno from e where fname=”neethu’);

Retrieve the names of employ who work on every project controlled by deptno=5
Select fname,lnamefrom employee where ((select pno from works-on26 where
eno=enum)contains (select pno from project26 where dno=5));

Retrieve the names of each employ who has a dependent with the same first name of
Select fname,lname from employ26 where eno in (select eno from dependent26 where

Retrieve the name of each employ who have no dependents

Select fname,lname from employ26 where NOT EXISTS(select * from dependent26
where eno=enum);

Retrieve the eno of all employees who works on project num 1,2,3
Select distinct eno from works-on26 where pno in(1,2);
Consider the following relations for the details maintained by a book dealer.
Catalog(bookid, title,authorid, publisherid, categoryid, year,price)
Category(categoryid, description)
Orderdetails(orderno, bookid, quantity)
Create the above tables properly by specifying the primary keys and foreign keys.
Enter altleast 4 to 5 tuples for each relation.

create table publisher26

(publisherid number(5),
name varchar2(20),
city varchar2(20),
country varchar2(20),
primary key(publisherid));

create table catalog26

(bookid number(5),
title varchar2(20),
authorid number(5),
publisherid number(5),
categoryid number(5),
year number(5),price decimal(5,2),
primary key(bookid),
foreign key(authorid) references author26(authorid),
foreign key(publisherid) references publisher26(publisherid),
foreign key(categoryid) references category26(catid));

create table category26

(catid number(5),
desc varchar2(10),
primary key(catid));

create table orderdetails26

(orderno number(5),
bookid number(5),
quantity number(5),
primary key(orderno),
foreign key(bookid) references catalog26(bookid));

1. Give the details of the author who have two or more books in the catalog and the
price of the books is greater than the average price of the books in the catalog and the
year of publication is after 2000.

2. Find the author of the book which has maximum sales .

3. Demonstrate how you increase the price of books published by a specific
publisher by 10%.

4. create a suitable front end for query and displaying the results.