P. 1
dbms lab

dbms lab

|Views: 30|Likes:
Published by anpsg1431139

More info:

Published by: anpsg1431139 on Dec 31, 2010
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as TXT, PDF, TXT or read online from Scribd
See more
See less

11/08/2012

pdf

text

original

1. Consider the Insurance database given below.

The primary keys are underlined and the data types are specified: PERSON (driver id #: String, name: string, address: string) CAR (regno: string, model: string, year: int) ACCIDENT (report-number: int, accd-date: date, location: string) OWNS (driver-id #:string, Regno:string) PARTICIPATED (driver-id: string, Regno:string, report-number:int, damage amou nt:int) (i) Create the above tables by properly specifying the primary keys and the foreign keys. Person create table person ( driverid varchar(5) primary key, name varchar(30), address varchar(50) ); Car create table car ( regno varchar(5) primary key, model varchar(25), year int ); Accident create table accident ( reportno int primary key, date1 date, location varchar(30) ); Owns create table owns ( driverid varchar(5) references person(driverid), regno varchar(5) references car(regno) ); Participated create table participated ( driverid varchar(5) references person(driverid) regno varchar(5) references car(regno) reportno int references accident(reportno) damages int, ); (ii) Enter at least five tuples for each relation. person insert insert insert insert into into into into person person person person values values values values (1,'abc','hkbkce,nagawara'); (2,'bcd','atria,yelahanka'); (3,'ade','ramahiah,near iisc'); (4,'cfg','mvjce,whitefield');

insert into person values (5,'rte','pesit,somewhere'); car insert insert insert insert insert insert into into into into into into car car car car car car values values values values values values ('a1','merc',2007); ('a2','porsche',2005); ('b2','rolls royce',2006); ('b4','ferrari',1999); ('c1','bentley',2000); ('d2','maybach',2007); (1,'1-01-2006','domlur'); (2,'28-03-2006','m.g.road'); (3,'2-12-2006','r.t.nagar'); (4,'5-01-2007','yelahanka'); (5,'26-01-2007','koramangla'); (6,'4-02-2007','majestic');

accident insert into insert into insert into insert into insert into insert into owns insert insert insert insert insert insert into into into into into into

accident accident accident accident accident accident owns owns owns owns owns owns

values values values values values values

values values values values values values

(1,'a1'); (2,'a2'); (2,'c1'); (3,'b2'); (4,'b4'); (5,'d2'); values values values values values values values values values values values values (1,'a1',1,500); (2,'a2',1,2000); (3,'b2',1,1000); (1,'a1',2,1500); (4,'c1',2,800); (5,'d2',3,750); (2,'c1',3,600); (1,'a1',3,200); (5,'d2',4,1000); (2,'a2',5,1200); (3,'b2',6,10000); (2,'a1',6,5000);

participated insert into participated insert into participated insert into participated insert into participated insert into participated insert into participated insert into participated insert into participated insert into participated insert into participated insert into participated insert into participated

(iii) Demonstrate how you a. Update the damage amount to 25000 for the car with a specific Regno in the AC CIDENT table with report number 12. update participated set damages=25000 where reportno=4 and regno='d2'; b. Add a new accident to the database. insert into accident values (7,'16-mar-2007','nagawara'); insert into participated values (2,'a1',7,15000); (iv) Find the total number of people who owned cars that were involved in accide nts in 2008. select count(distinct p.driverid) from accident a,owns o,participated p where date1 like '%06' and a.reportno=p.reportno and p.regno=o.regno and o.driverid=p.driverid; (v) Find the number of accidents in which cars belonging to a specific model wer

e involved. select count(*) from car c,participated p where model='porsche' and c.regno= p.regno;

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->