Dbms lab 01 termwork1

735 views
661 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
735
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Dbms lab 01 termwork1

  1. 1. INSURANCE DATABASE SQL> create table person 2 (driver_id varchar(5) primary key,name char(10), 3 address varchar(10)); Table created. SQL> desc person; Name Null? Type ------------------------------- -------- ---- DRIVER_ID NOT NULL VARCHAR2(5) NAME CHAR(10) ADDRESS VARCHAR2(10) SQL> insert into person 2 values('&driver_id','&name','&address'); Enter value for driver_id: 111 Enter value for name: vijay Enter value for address: bgm old 2: values('&driver_id','&name','&address') new 2: values('111','vijay','bgm') SGI’S BELGAUM INSTITUTE OF MANAGEMENT STUDIES [BIMS] DEGREE COLLEGE SHAIKH CAMPUS NEHRU NAGAR BELGAUM Page 1
  2. 2. INSURANCE DATABASE 1 row created. SQL> / Enter value for driver_id: 222 Enter value for name: salman Enter value for address: goa old 2: values('&driver_id','&name','&address') new 2: values('222','salman','goa') 1 row created. SQL> / Enter value for driver_id: 333 Enter value for name: sam Enter value for address: bgm old 2: values('&driver_id','&name','&address') new 2: values('333','sam','bgm') 1 row created. SQL> / Enter value for driver_id: 444 SGI’S BELGAUM INSTITUTE OF MANAGEMENT STUDIES [BIMS] DEGREE COLLEGE SHAIKH CAMPUS NEHRU NAGAR BELGAUM Page 2
  3. 3. INSURANCE DATABASE Enter value for name: ganesh Enter value for address: nepal old 2: values('&driver_id','&name','&address') new 2: values('444','ganesh','nepal') 1 row created. SQL> / Enter value for driver_id: 555 Enter value for name: reshma Enter value for address: bgm old 2: values('&driver_id','&name','&address') new 2: values('555','reshma','bgm') 1 row created. SQL> select * from person; DRIVE NAME ADDRESS ----- ---------- ---------- 111 vijay bgm 222 salman goa SGI’S BELGAUM INSTITUTE OF MANAGEMENT STUDIES [BIMS] DEGREE COLLEGE SHAIKH CAMPUS NEHRU NAGAR BELGAUM Page 3
  4. 4. INSURANCE DATABASE 333 sam bgm 444 ganesh nepal 555 reshma bgm SQL> create table car 2 (reg_no varchar(10) primary key,model varchar(5),year number(5 Table created. SQL> desc car; Name Null? Type ------------------------------- -------- ---- REG_NO NOT NULL VARCHAR2(10) MODEL VARCHAR2(5) YEAR NUMBER(5) SGI’S BELGAUM INSTITUTE OF MANAGEMENT STUDIES [BIMS] DEGREE COLLEGE SHAIKH CAMPUS NEHRU NAGAR BELGAUM Page 4
  5. 5. INSURANCE DATABASE SQL> insert into car 2 values('&reg_no','&model',&year); Enter value for reg_no: a111 Enter value for model: i10 Enter value for year: 2006 old 2: values('&reg_no','&model',&year) new 2: values('a111','i10',2006) 1 row created. SQL> / Enter value for reg_no: b222 Enter value for model: i20 Enter value for year: 2010 old 2: values('&reg_no','&model',&year) new 2: values('b222','i20',2010) 1 row created. SQL> / SGI’S BELGAUM INSTITUTE OF MANAGEMENT STUDIES [BIMS] DEGREE COLLEGE SHAIKH CAMPUS NEHRU NAGAR BELGAUM Page 5
  6. 6. INSURANCE DATABASE Enter value for reg_no: c333 Enter value for model: alto Enter value for year: 2002 old 2: values('&reg_no','&model',&year) new 2: values('c333','alto',2002) 1 row created. SQL> / Enter value for reg_no: d444 Enter value for model: bmw Enter value for year: 2005 old 2: values('&reg_no','&model',&year) new 2: values('d444','bmw',2005) 1 row created. SQL> / Enter value for reg_no: e555 Enter value for model: audi Enter value for year: 2003 old 2: values('&reg_no','&model',&year) new 2: values('e555','audi',2003) SGI’S BELGAUM INSTITUTE OF MANAGEMENT STUDIES [BIMS] DEGREE COLLEGE SHAIKH CAMPUS NEHRU NAGAR BELGAUM Page 6
  7. 7. INSURANCE DATABASE 1 row created. SQL> select * from car; REG_NO MODEL YEAR ---------- ----- --------- a111 i10 2006 b222 i20 2010 c333 alto 2002 d444 bmw 2005 e555 audi 2003 SQL> create table accident 2 (report_no number(5) primary key, acc_date date,location varchar(10)); SGI’S BELGAUM INSTITUTE OF MANAGEMENT STUDIES [BIMS] DEGREE COLLEGE SHAIKH CAMPUS NEHRU NAGAR BELGAUM Page 7
  8. 8. INSURANCE DATABASE Table created. SQL> desc accident; Name Null? Type ------------------------------- -------- ---- REPORT_NO NOT NULL NUMBER(5) ACC_DATE DATE LOCATION VARCHAR2(10) SQL> insert into accident 2 values(&report_no,'&acc_date','&location'); Enter value for report_no: 1 Enter value for acc_date: 1-jan-2001 Enter value for location: bgm old 2: values(&report_no,'&acc_date','&location') new 2: values(1,'1-jan-2001','bgm') 1 row created. SQL> / SGI’S BELGAUM INSTITUTE OF MANAGEMENT STUDIES [BIMS] DEGREE COLLEGE SHAIKH CAMPUS NEHRU NAGAR BELGAUM Page 8
  9. 9. INSURANCE DATABASE Enter value for report_no: 2 Enter value for acc_date: 25-dec-2006 Enter value for location: goa old 2: values(&report_no,'&acc_date','&location') new 2: values(2,'25-dec-2006','goa') 1 row created. SQL> / Enter value for report_no: 3 Enter value for acc_date: 12-june-2003 Enter value for location: bgm old 2: values(&report_no,'&acc_date','&location') new 2: values(3,'12-june-2003','bgm') 1 row created. SQL> / Enter value for report_no: 4 Enter value for acc_date: 31-dec-2003 Enter value for location: bgm old 2: values(&report_no,'&acc_date','&location') new 2: values(4,'31-dec-2003','bgm') SGI’S BELGAUM INSTITUTE OF MANAGEMENT STUDIES [BIMS] DEGREE COLLEGE SHAIKH CAMPUS NEHRU NAGAR BELGAUM Page 9
  10. 10. INSURANCE DATABASE 1 row created. SQL> / Enter value for report_no: 5 Enter value for acc_date: 2-jan-2004 Enter value for location: goa old 2: values(&report_no,'&acc_date','&location') new 2: values(5,'2-jan-2004','goa') 1 row created. SQL> select * from accident; REPORT_NO ACC_DATE LOCATION --------- --------- ---------- 1 01-JAN-01 bgm 2 25-DEC-06 goa 3 12-JUN-03 bgm 4 31-DEC-03 bgm 5 02-JAN-04 goa SQL> create table owns SGI’S BELGAUM INSTITUTE OF MANAGEMENT STUDIES [BIMS] DEGREE COLLEGE SHAIKH CAMPUS NEHRU NAGAR BELGAUM Page 10
  11. 11. INSURANCE DATABASE 2 (driver_id varchar(5), reg_no varchar(10), 3 foreign key(driver_id) references person(driver_id), 4 foreign key(reg_no) references car(reg_no)); Table created. SQL> desc owns; Name Null? Type ------------------------------- -------- ---- DRIVER_ID VARCHAR2(5) REG_NO VARCHAR2(10) SQL> insert into owns 2 values('&driver_id','&reg_no'); Enter value for driver_id: 111 Enter value for reg_no: a111 old 2: values('&driver_id','&reg_no') new 2: values('111','a111') 1 row created. SGI’S BELGAUM INSTITUTE OF MANAGEMENT STUDIES [BIMS] DEGREE COLLEGE SHAIKH CAMPUS NEHRU NAGAR BELGAUM Page 11
  12. 12. INSURANCE DATABASE SQL> / Enter value for driver_id: 222 Enter value for reg_no: b222 old 2: values('&driver_id','&reg_no') new 2: values('222','b222') 1 row created. SQL> / Enter value for driver_id: 333 Enter value for reg_no: c333 old 2: values('&driver_id','&reg_no') new 2: values('333','c333') 1 row created. SQL> / Enter value for driver_id: 444 Enter value for reg_no: d444 old 2: values('&driver_id','&reg_no') new 2: values('444','d444') SGI’S BELGAUM INSTITUTE OF MANAGEMENT STUDIES [BIMS] DEGREE COLLEGE SHAIKH CAMPUS NEHRU NAGAR BELGAUM Page 12
  13. 13. INSURANCE DATABASE 1 row created. SQL> / Enter value for driver_id: 555 Enter value for reg_no: e555 old 2: values('&driver_id','&reg_no') new 2: values('555','e555') 1 row created. SQL> select * from owns; DRIVE REG_NO ----- ---------- 111 a111 222 b222 333 c333 444 d444 555 e555 SGI’S BELGAUM INSTITUTE OF MANAGEMENT STUDIES [BIMS] DEGREE COLLEGE SHAIKH CAMPUS NEHRU NAGAR BELGAUM Page 13
  14. 14. INSURANCE DATABASE SQL> commit; Commit complete. SQL> create table participated 2 (driver_id varchar(5),reg_no varchar(10),report_no number(5), 3 damage_amt number(6), 4 foreign key(driver_id) references person(driver_id), 5 foreign key(reg_no) references car(reg_no), 6 foreign key(report_no) references accident(report_no)); Table created. SQL> desc participated; Name Null? Type ------------------------------- -------- ---- DRIVER_ID VARCHAR2(5) REG_NO VARCHAR2(10) REPORT_NO NUMBER(5) DAMAGE_AMT NUMBER(6) SGI’S BELGAUM INSTITUTE OF MANAGEMENT STUDIES [BIMS] DEGREE COLLEGE SHAIKH CAMPUS NEHRU NAGAR BELGAUM Page 14
  15. 15. INSURANCE DATABASE SQL> insert into participated 2 values('&driver_id','&reg_no',&report_no,&damage_amt); Enter value for driver_id: 111 Enter value for reg_no: a111 Enter value for report_no: 1 Enter value for damage_amt: 15000 old 2: values('&driver_id','&reg_no',&report_no,&damage_amt) new 2: values('111','a111',1,15000) 1 row created. SQL> / Enter value for driver_id: 222 Enter value for reg_no: b222 Enter value for report_no: 2 Enter value for damage_amt: 10000 old 2: values('&driver_id','&reg_no',&report_no,&damage_amt) new 2: values('222','b222',2,10000) 1 row created. SQL> / Enter value for driver_id: 333 Enter value for reg_no: c333 Enter value for report_no: 3 Enter value for damage_amt: 30000 SGI’S BELGAUM INSTITUTE OF MANAGEMENT STUDIES [BIMS] DEGREE COLLEGE SHAIKH CAMPUS NEHRU NAGAR BELGAUM Page 15
  16. 16. INSURANCE DATABASE old 2: values('&driver_id','&reg_no',&report_no,&damage_amt) new 2: values('333','c333',3,30000) 1 row created. SQL> / Enter value for driver_id: 444 Enter value for reg_no: d444 Enter value for report_no: 4 Enter value for damage_amt: 12000 old 2: values('&driver_id','&reg_no',&report_no,&damage_amt) new 2: values('444','d444',4,12000) 1 row created. SQL> / Enter value for driver_id: 555 Enter value for reg_no: e555 Enter value for report_no: 5 Enter value for damage_amt: 50000 old 2: values('&driver_id','&reg_no',&report_no,&damage_amt) new 2: values('555','e555',5,50000) 1 row created. SQL> select * from participated; SGI’S BELGAUM INSTITUTE OF MANAGEMENT STUDIES [BIMS] DEGREE COLLEGE SHAIKH CAMPUS NEHRU NAGAR BELGAUM Page 16
  17. 17. INSURANCE DATABASE DRIVE REG_NO REPORT_NO DAMAGE_AMT ----- ---------- --------- ---------- 111 a111 1 15000 222 b222 2 10000 333 c333 3 30000 444 d444 4 12000 555 e555 5 50000 QUERY 1 : UPDATE THE DAMAGE AMOUNT FOR THE CAR WITH A REGISTER NUMBER,IN THE ACCIDENT WITH REPORT NUMBER 12 TO 25000. SQL> SQL> update participated 2 set damage_amt=25000 3 where reg_no='&reg_no'AND report_no=1; Enter value for reg_no: a111 old 3: where reg_no='&reg_no'AND report_no=1 new 3: where reg_no='a111'AND report_no=1 1 row updated. SGI’S BELGAUM INSTITUTE OF MANAGEMENT STUDIES [BIMS] DEGREE COLLEGE SHAIKH CAMPUS NEHRU NAGAR BELGAUM Page 17
  18. 18. INSURANCE DATABASE SQL> select * from participated; DRIVE REG_NO REPORT_NO DAMAGE_AMT ----- ---------- --------- ---------- 111 a111 1 25000 222 b222 2 10000 333 c333 3 30000 444 d444 4 12000 555 e555 5 50000 QUERY 2 : ADD A NEW ACCIDENT TO THE DATABASE. SQL> insert into accident 2 values(6,'12-apr-2001','delhi'); 1 row created. SQL> select * from accident; REPORT_NO ACC_DATE LOCATION --------- --------- ---------- 1 01-JAN-01 bgm 2 25-DEC-06 goa 3 12-JUN-03 bgm SGI’S BELGAUM INSTITUTE OF MANAGEMENT STUDIES [BIMS] DEGREE COLLEGE SHAIKH CAMPUS NEHRU NAGAR BELGAUM Page 18
  19. 19. INSURANCE DATABASE 4 31-DEC-03 bgm 5 02-JAN-04 goa 6 12-APR-01 delhi 6 rows selected. SQL> select * from accident; REPORT_NO ACC_DATE LOCATION --------- --------- ---------- 1 01-JAN-01 bgm 2 25-DEC-06 goa 3 12-JUN-03 bgm 4 31-DEC-03 bgm 5 02-JAN-04 goa 6 12-APR-01 delhi 6 rows selected. Query 4 : FIND THE TOTAL NUMBER OF PEOPLE WHO OWNED CARS THAT WHERE INVOLVED IN ACCIDENTS IN YEAR 2003 SQL> select count(*) AS Total_No_Of_Persons 2 from person p,accident a,participated d 3 where acc_date like '%03'AND SGI’S BELGAUM INSTITUTE OF MANAGEMENT STUDIES [BIMS] DEGREE COLLEGE SHAIKH CAMPUS NEHRU NAGAR BELGAUM Page 19
  20. 20. INSURANCE DATABASE 4 d.driver_id=p.driver_id 5 AND a.report_no=d.report_no; TOTAL_NO_OF_PERSONS ------------------- 2 QUERY 5 : FIND THE NUMBER OF ACCIDENTS IN WHICH CARS BELONGING TO A SPECIFIC MODEL WHERE INVOLVED. SQL> select count(*) AS Total_No_Of_Accident 2 from accident a,car c, participated p 3 where model='&model' AND p.reg_no=c.reg_no AND 4 a.report_no=p.report_no; Enter value for model: i10 old 3: where model='&model' AND p.reg_no=c.reg_no AND new 3: where model='i10' AND p.reg_no=c.reg_no AND TOTAL_NO_OF_ACCIDENT -------------------- 1 SGI’S BELGAUM INSTITUTE OF MANAGEMENT STUDIES [BIMS] DEGREE COLLEGE SHAIKH CAMPUS NEHRU NAGAR BELGAUM Page 20
  21. 21. INSURANCE DATABASE SQL> select * from car; REG_NO MODEL YEAR ---------- ----- --------- a111 i10 2006 b222 i20 2010 c333 alto 2002 d444 bmw 2005 e555 audi 2003 ************************* END OF TERM WORK 1************************** SGI’S BELGAUM INSTITUTE OF MANAGEMENT STUDIES [BIMS] DEGREE COLLEGE SHAIKH CAMPUS NEHRU NAGAR BELGAUM Page 21

×