Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Case study

many to one

Person- Area

Person (p_number, p_name, birthdate, income)

Area (a_name , a_type, pincode )

Person-area : many to one

The area type can be have values as either urban or ruler.

Create area table

=>create table area (a_name varchar(20) primary key,a_type varchar(10) check('urban'or'rural'),pincode


int not null);

create person table and assign primay key of area table as foreign key.

=>create table peson (p_no int primay key ,p_name varchar(20) ,birthdate date ,income float not null ,
a_name varchar(10) , foreign key(a_name) REFERENCES area(a_name));

Insert values in both table

QUERIES.

1. List the name of people who live in camp area and have income less than 500000
=>select * from area,person where area.a_name =person.a_name and person.a_name = ‘camp’
and income < 500000;
2. Count the number of person living in area type urban
=> select count(*) from area,person where area.a_name =person.a_name and area.a_type =
‘urban’;
3. List the name of people whose birthday falls in the month of July
=>select * from person where extract(month from birthdate)=7;
4. Change the pin code of kalyani Nagar to 411036
=>update area set pincode = 411036 where a_name =’kalyani nagar’;
5. Display the information of person in ascending order of income.
=>select * from person order by income ;
6. Display the information of person in descending order of income.
=>select * from person order by income desc ;
7. List display total number of person living in camp area
=>select a_name ,count(*) from person group by a_name having a_name= ‘camp’ ;
8. Display total number of persons living in different areas.
=>select a_name ,count(*) from person group by a_name ;
Room- guest

Room(room_no,room_name, room_type, charges)

Guest (guest _no, guest_name, city)

Room -guest : one to one

Create room table

=>create table room (room_no int primary key, room_name varchar(10),room_type varchar(10)
check('AC'or'NonAC'),charges int not null);

Create guest table

=>create table guest (guest_no int primay key ,guest_name varchar(20) ,city varchar(10) , room_no int ,
foreign key(room_no) REFERENCES room(room_no));

Insert values in both table

QUERIES.

1. Display all the details of all guests who booked room F1


=>select * from room,guest where room.room_no =guest.room_no and room_name = ‘F1’;
2. List the details of room allocated to Mr. ram
=>select * from room,guest where room.room_no =guest.room_no and guest_name = ‘Mr. ram’;
3. Display count of all guests living in AC room
=>select count(*) from guest,room where room.room_no =guest.room_no and room_type =
‘AC’;
4. Change room of Mr. saho from F1 to S1
=>
5. Delete all guest from Pune city.
=>delete from guest where city= ‘pune’;

You might also like