Dbms Lab Programs(1)

download Dbms Lab Programs(1)

of 23

  • date post

    03-Apr-2018
  • Category

    Documents

  • view

    273
  • download

    5

Embed Size (px)

Transcript of Dbms Lab Programs(1)

  • 7/29/2019 Dbms Lab Programs(1)

    1/23

    Govt Engineering college k r pete

    Database Applications Laboratory

    1

    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,date:date,location:string)OWNS (driver-id:string,regno:string)

    PARTICIPATED (driver-id:string,regno:string,report-number:int,damage-amount:int)

    i) create the above tables by properly specifying the primary keys and the foreign keys

    ii) Enter atleast five tuples for each relation

    iii) Demonstrate how you

    a. Update the damage amount for the car with a specific regno in accident with

    report number 12 to 25000

    b. Add a new accident to the database

    iv) Find the total number of people who owned cars that were involved in accidents in

    2006.

    v) Find the number of accidents in which cars belonging to a specific model were

    involved.

    vi) Generation of suitable reports

    vii)Create suitable front end for querying and display the results

    create table person

    (

    driverid varchar(5) primary key,

    name varchar(30),

    address varchar(50));

    create table car

    (

    regno varchar(5) primary key,

    model varchar(25),

    year int

    );

    create table accident

    (reportno int primary key,

    date1 date,

    location varchar(30)

    );

    create table owns

    (

    driverid references person,

    regno references car

    );

  • 7/29/2019 Dbms Lab Programs(1)

    2/23

    Govt Engineering college k r pete

    Database Applications Laboratory

    2

    create table participated

    (

    driverid references person,

    regno references car,

    reportno references accident,damages int

    );

    insert into person values (1,'abc','hkbkce,nagawara');

    insert into person values (2,'bcd','atria,yelahanka');

    insert into person values (3,'ade','ramahiah,near iisc');

    insert into person values (4,'cfg','mvjce,whitefield');

    insert into person values (5,'rte','pesit,somewhere');

    insert into car values ('a1','merc',2007);

    insert into car values ('a2','porsche',2005);

    insert into car values ('b2','rolls royce',2006);

    insert into car values ('b4','ferrari',1999);

    insert into car values ('c1','bentley',2000);

    insert into car values ('d2','maybach',2007);

    insert into accident values (1,'1-jan-2006','domlur');

    insert into accident values (2,'28-mar-2006','m.g.road');

    insert into accident values (3,'2-dec-2006','r.t.nagar');

    insert into accident values (4,'5-jan-2007','yelahanka');

    insert into accident values (5,'26-jan-2007','koramangla');insert into accident values (6,'4-feb-2007','majestic');

    insert into owns values (1,'a1');

    insert into owns values (2,'a2');

    insert into owns values (2,'c1');

    insert into owns values (3,'b2');

    insert into owns values (4,'b4');

    insert into owns values (5,'d2');

    insert into participated values (1,'a1',1,500);

    insert into participated values (2,'a2',1,2000);insert into participated values (3,'b2',1,1000);

    insert into participated values (1,'a1',2,1500);

    insert into participated values (4,'c1',2,800);

    insert into participated values (5,'d2',3,750);

    insert into participated values (2,'c1',3,600);

    insert into participated values (1,'a1',3,200);

    insert into participated values (5,'d2',4,1000);

    insert into participated values (2,'a2',5,1200);

    insert into participated values (3,'b2',6,10000);

    insert into participated values (2,'a1',6,5000);

  • 7/29/2019 Dbms Lab Programs(1)

    3/23

    Govt Engineering college k r pete

    Database Applications Laboratory

    3

    select * from person;

    DRIVERID NAME ADDRESS

    ---------------- ---------- ----------------------

    1 abc hkbkce,nagawara

    2 bcd atria,yelahanka

    3 ade ramahiah,near iisc4 cfg mvjce,whitefield

    5 rte pesit,somewhere

    select * from car;

    REGNO MODEL YEAR

    ----------- ---------------- ------------

    a1 merc 2007

    a2 porsche 2005

    b2 rolls royce 2006

    b4 ferrari 1999

    c1 bentley 2000

    d2 maybach 2007

    select * from accident;

    REPORTNO DATE1 LOCATION

    ----------------- -------------- -----------------------

    1 01-JAN-06 domlur

    2 28-MAR-06 m.g.road

    3 02-DEC-06 r.t.nagar

    4 05-JAN-07 yelahanka

    5 26-JAN-07 koramangla6 04-FEB-07 majestic

    select * from owns;

    DRIVERID REGNO

    -------------- -----------

    1 a1

    2 a2

    2 c1

    3 b2

    4 b4

    5 d2

    select * from participated;

    DRIVERID REGNO REPORTNO DAMAGES

    ---------------- ----------- ----------------- ----------------

    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 6001 a1 3 200

  • 7/29/2019 Dbms Lab Programs(1)

    4/23

    Govt Engineering college k r pete

    Database Applications Laboratory

    4

    5 d2 4 1000

    2 a2 5 1200

    3 b2 6 10000

    2 a1 6 5000

    iii.a Update the damage amount for the car with a specific regno in accident with reportnumber 12 to 25000

    update participated set damages=25000 where reportno=4 and regno='d2';

    1 row updated

    select * from participated;

    DRIVERID REGNO REPORTNO DAMAGES

    ---------------- ----------- ----------------- ----------------

    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 25000

    2 a2 5 1200

    3 b2 6 10000

    2 a1 6 5000

    iii.b Add a new accident to the database

    insert into accident values (7,'16-mar-2007','nagawara');

    1 row updated

    insert into participated values (2,'a1',7,15000);

    1 row updated

    select * from accident;

    REPORTNO DATE1 LOCATION----------------- -------------- -----------------------

    1 01-JAN-06 domlur

    2 28-MAR-06 m.g.road

    3 02-DEC-06 r.t.nagar

    4 05-JAN-07 yelahanka

    5 26-JAN-07 koramangla

    6 04-FEB-07 majestic

    7 16-MAR-07 nagawara

  • 7/29/2019 Dbms Lab Programs(1)

    5/23

    Govt Engineering college k r pete

    Database Applications Laboratory

    5

    select * from participated;

    DRIVERID REGNO REPORTNO DAMAGES

    ---------------- ----------- ----------------- ----------------

    1 a1 1 500

    2 a2 1 2000

    3 b2 1 10001 a1 2 1500

    4 c1 2 800

    5 d2 3 750

    2 c1 3 600

    1 a1 3 200

    5 d2 4 25000

    2 a2 5 1200

    3 b2 6 10000

    2 a1 6 5000

    2 a1 7 15000

    iv. Find the total number of people who owned cars that were involved in accidents in 2006

    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;

    COUNT(DISTINCTP.DRIVERID)

    ---------------------------------------------

    4

    v. Find the number of accidents in which cars belonging to a specific model were involved.select count(*) from car c,participated p where model='porsche' and c.regno=p.regno;

    COUNT(*)

    --------------

    2

  • 7/29/2019 Dbms Lab Programs(1)

    6/23

    Govt Engineering college k r pete

    Database Applications Laboratory

    6

    2. Consider the following relations for an order processing database application in a

    company.

    CUSTOMER(Cust #: int, Cname: string, City: string)

    ORDER(Order #: int, Odate: date, Cust #: int, Ord-Amt: int)

    ORDER-ITEM (Order #: int, Item #: int, qty: int)ITEM (Item #: int, Unit Price: int)

    SHIPMENT (Order #: int, Warehouse #: int, Ship-Date: date)

    WAREHOUSE (Warehouse #: int, City: string)

    i) Create the above tables by properly specifying the primary keys and the foreign keys.

    ii) Enter at least five tuples for each relation.

    iii) Produce a listing: CUSTNAME, NO_OF_ORDERS, AVG_ORDER_AMT, where

    the middle column is the total number of orders by the customer and the last column

    is the average order amount for that customer.

    iv) List the Order# for the orders that were shipped from all the warehouses that the

    company has in a specific city.

    v) Demonstrate how you delete Item# 10 from the ITEM table and make that field nullin the ORDER-ITEM table.

    vi) Generation of suitable reports.

    vii) Create a suitable front end for querying and displaying the results.

    create table customer

    (

    cno int primary key,

    cname varchar(10),

    city varchar(15));

    create table order1

    (

    ono int primary key,

    odate date,

    cno references customer,

    oamt int

    );

    create table item(

    ino int primary key,

    uprice int

    );

    create table oitem

    (

    ono references order1,

    ino references item on delete set null,

    qty int

    );

  • 7/29/2019 Dbms Lab Programs(1)

    7/23

    Govt Engineering college k r pete

    Database Applications Laboratory

    7

    create table warehouse

    (

    wno int primary key,

    city varchar(15)

    );

    create table shipment

    (

    ono references order1,

    wno references warehouse,

    sdate date

    );

    insert into customer values(1,'abc','bangalore');

    insert into customer values(2,'cde','mysore');

    insert into customer values(3,'def','chennai');

    insert into customer values(4,'efg','mumbai');

    insert into customer values(5,'adf','