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

create table PERSON(DRIVER_ID_NO VARCHAR(12),NAME VARCHAR(12),

ADDRESS VARCHAR(33),CONSTRAINT PK11 PRIMARY KEY(DRIVER_ID_NO));


create table CAR(REGNO VARCHAR(12),MODEL VARCHAR(12),YEAR INTEGER,
CONSTRAINT PK12 PRIMARY KEY(REGNO));
create table ACCIDENT(REPORTNO INTEGER,DATE1 DATE,LOCATION VARCHAR(12),
CONSTRAINT PK13 PRIMARY KEY(REPORTNO));
create table OWNS(DRIVER_ID_NO VARCHAR(12),CONSTRAINT FK11 FOREIGN KEY(
DRIVER_ID_NO) REFERENCES PERSON(DRIVER_ID_NO),REGNO VARCHAR(12),CONSTRAINT FK12
FOREIGN KEY(REGNO) REFERENCES CAR(REGNO),CONSTRAINT PK14 PRIMARY KEY(REGNO,DRIVE
R_ID_NO));
create table PARTICIPATED(DRIVER_ID_NO VARCHAR(12),CONSTRAINT FK13 FORE
IGN KEY(DRIVER_ID_NO) REFERENCES PERSON(DRIVER_ID_NO), REGNO VARCHAR(12), CONSTR
AINT FK14 FOREIGN KEY(REGNO) REFERENCES CAR(REGNO),REPORTNO INTEGER, CONSTRAINT
FK15 FOREIGN KEY(REPORTNO) REFERENCES ACCIDENT(REPORTNO),DAMAGEDAMOUNT INTEGER,C
ONSTRAINT PK15 PRIMARY KEY(DRIVER_ID_NO,REGNO,REPORTNO));

delete from person;


insert into person values('A11','ranjan','bangalore');
insert into person values('A22','nadeem','mangalore');
insert into person values('A33','ananth','mysore');
insert into person values('A44','manav','shimoga');
insert into person values('A55','bhairav','dharwad');
delete from CAR;
insert into CAR values('KA02E1235','zen','1986');
insert into CAR values('KA02E1231','alto','1987');
insert into CAR values('KA02E1222','zen','1988');
insert into CAR values('KA02E1232','zen','1989');
insert into CAR values('KA02E1233','alto','1999');

delete from ACCIDENT;


insert into ACCIDENT values('11','02-JAN-2001','BANGALORE');
insert into ACCIDENT values('12','03-FEB-2002','BANGALORE');
insert into ACCIDENT values('13','03-OCT-2001','BANGALORE');
insert into ACCIDENT values('14','12-SEP-2002','BANGALORE');
insert into ACCIDENT values('15','09-SEP-2002','BANGALORE');
delete from OWNS;
insert into OWNS values('A11','KA02E1235');
insert into OWNS values('A22','KA02E1231');
insert into OWNS values('A33','KA02E1222');
insert into OWNS values('A44','KA02E1233');
insert into OWNS values('A55','KA02E1233');

delete from PARTICIPATED;


insert into PARTICIPATED values('A11','KA02E1235','11','1000');
insert into PARTICIPATED values('A22','KA02E1231','12','2000');
insert into PARTICIPATED values('A33','KA02E1222','13','3000');
insert into PARTICIPATED values('A44','KA02E1233','14','4000');
insert into PARTICIPATED values('A55','KA02E1233','15','5000');
commit;
SELECT * FROM PARTICIPATED;
SELECT * FROM CAR;
SELECT * FROM OWNS;
SELECT * FROM ACCIDENT;
SELECT * FROM PERSON;

update participated set damagedamount-'25000'where(reportno-'12'and regno-'ka02e


1231');
insert into accident values('33','01/sep/2002','bangalore');

select count(*) from accident a, participated p, person pe where((p.reportno=a.r


eportno)and p.driver_id_no=pe.driver_id_no)and(date1 like '%02'));

select car.model,count(*)from car,accident,participated where((accident.reportno


=participated.reportno)and(participated.regno))group by car.model;