You are on page 1of 3

RDBMS – ASSIGNMENT 4

1. Consider the following Database of Bus transport system . Many buses run
on one route.
Drivers are allotted to the buses shiftwise.
Following are the tables:
BUS (BUS_NO INT , CAPACITY INT , DEPOT_NAME VARCHAR(20))
ROUTE (ROUTE_NO INT, SOURCE CHAR(20), DESTINATION CHAR(20),
NO_OF_STATIONS INT)
DRIVER (DRIVER_NO INT , DRIVER_NAME CHAR(20), LICENSE_NO INT,
ADDRESSCHAR(20), D_AGE INT , SALARY FLOAT)
The relationships are as follows:
BUS_ROUTE : M-1
BUS_DRIVER (bno,dno,dated,shift) M-M with descriptive attributes Date of duty allotted and
Shift — it can be
(Morning) or ( Evening ).
Constraints: 1. License_no is unique. 2. Bus capacity is not null.

Creating tables:

fybc=# create table route (rno int primary key, source varchar(20), destination
varchar(20), no_of_stations int);
CREATE TABLE

fybc=# create table bus (bno int primary key, capacity int not null, depot_name varchar(20),
rno int references route(rno) on delete cascade on update set null);
CREATE TABLE

fybc=# create table driver (dno int primary key, dname varchar(20), license_no int unique,
address varchar(20), d_age int, salary float);
CREATE TABLE

fybc=# create table bus_driver (bno int references bus(bno) on delete cascade on update set null,
dno int references driver(dno) on delete cascade on update set null, date_of_duty date, shift
varchar(20) check(shift in ('morning','evening')));
CREATE TABLE

Inserting Values:

fybc=# insert into route values (64001,'pune','lucknow',10),(64101,'kochi','bengaluru',7),(64120,


'mumbai','goa',12);
INSERT 0 3

fybc=# insert into bus values (101,50,'mumbai central',64120), (102,30,'pune central',64001),


(103,40,'ernakulam',64101), (104,40,'deccan',64001), (105,50,'edappally',64101);
INSERT 0 5

SWARALI PRABHU 1132210104 FYBCA-


A
RDBMS – ASSIGNMENT 4

fybc=# insert into driver values


(121,'Ram',124201,'pune',42,32000),
(122,'Sham',134209,'mumbai',40,25000),
(123,'Laxman',142301,'kochi',45,45000);
INSERT 0 3
fybc=# insert into bus_driver values (101,122,'10-12- 2021','evening'),(105,123,'30-12-
2021','evening'),(102,121,'03-
01-2022','morning'),(104,121,'10-01-
2022','evening'),(103,123,'15-01-2022','morning'); INSERT 0 5
Tables:

trim2=# select * from route;


rno | source | destination | no_of_stations
+ + +
64001 | pune | lucknow | 10

64101 | kochi | bengaluru | 7


64120 | mumbai | goa | 12

(3 rows)
trim2=# select * from bus;
bno | capacity | depot_name | rno
+ + +
101 | 50 | mumbai central | 64120
102 | 30 | pune central | 64001
103 | 40 | ernakulam | 64101 104 | 40 |
deccan | 64001
105 | 50 | edappally | 64101 (5 rows)
trim2=# select * from driver;
dno | dname | license_no | address | d_age | salary
+ + + + +
121 | Ram | 124201 | pune | 42 | 32000
122 | Sham | 134209 | mumbai | 40 | 25000
123 | Laxman | 142301 | kochi | 45 | 45000

(3 rows)

SWARALI PRABHU 1132210104 FYBCA-


A
Thank you for using www.freepdfconvert.com service!

Only two pages are converted. Please Sign Up to convert all pages.

https://www.freepdfconvert.com/membership

You might also like