0% found this document useful (0 votes)
166 views4 pages

SQL Schema and Queries for Hostel Management

The document describes tables created to store data about hostels, rooms, students, fees etc. in an Oracle database. The tables are: 1) HOSTEL - Stores hostel details like hostel number, name, total capacity, warden 2) ROOM - Stores room details like number, hostel number, type, location, occupancy, status 3) CHARGES - Stores room charges based on hostel and room type 4) STUDENT - Stores student details and their assigned hostel and room 5) FEES - Stores fees paid by students along with date The document also lists 15 sample queries that can be run on the tables.

Uploaded by

Krunal Patel
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
166 views4 pages

SQL Schema and Queries for Hostel Management

The document describes tables created to store data about hostels, rooms, students, fees etc. in an Oracle database. The tables are: 1) HOSTEL - Stores hostel details like hostel number, name, total capacity, warden 2) ROOM - Stores room details like number, hostel number, type, location, occupancy, status 3) CHARGES - Stores room charges based on hostel and room type 4) STUDENT - Stores student details and their assigned hostel and room 5) FEES - Stores fees paid by students along with date The document also lists 15 sample queries that can be run on the tables.

Uploaded by

Krunal Patel
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

HOSTEL (H#, hname, haddr, total_capacity, warden)

SQL> CREATE TABLE HOSTEL(


2 HNO VARCHAR2(5) PRIMARY KEY,
3 HNAME VARCHAR2(20),
4 CAPACITY NUMBER(5),
5 WARDEN VARCHAR2(20));
ROOM (h#, r#, rtype, location, no_of_students, status)
SQL> CREATE TABLE ROOM(
2 RNO VARCHAR2(5) PRIMARY KEY,
3 HNO VARCHAR2(5) REFERENCES HOSTEL,
4 RTYPE VARCHAR2(1) CHECK(RTYPE IN('S','D','T','F')),
5 LOCATION VARCHAR2(10),
6 NO_OF_STD NUMBER(5),
7 STATUS VARCHAR2(10));
CHARGES (h#, rtype, charges)
SQL> CREATE TABLE CHARGES(
2 HNO VARCHAR2(5) REFERENCES HOSTEL,
3 RTYPE VARCHAR2(1) CHECK(RTYPE IN('S','D','T','F')),
4 CHARGES NUMBER(7,2));
STUDENT (sid, sname, saddr, faculty, dept, class, h#, r#)
SQL> CREATE TABLE STUDENT(
2 SID VARCHAR2(5) PRIMARY KEY,
3 SNAME VARCHAR2(20),
4 SADDR VARCHAR2(25),
5 COURCE VARCHAR2(10),
6 DEPT VARCHAR2(10),
7 CLASS VARCHAR2(8),
8 HNO VARCHAR2(5) REFERENCES HOSTEL,
9 RNO VARCHAR2(5) REFERENCES ROOM);
FEES (sid, fdate, famount)
SQL> CREATE TABLE FEES(
2 SID VARCHAR2(5) REFERENCES STUDENT,
3 FDATE DATE,
4 FAMOUNT NUMBER(7,2));

SQL> INSERT INTO HOSTEL VALUES('&HNO','&HNAME',&CAPACITY,'&WARDEN');


SQL> INSERT INTO ROOM VALUES('&RNO','&HNO','&RTYPE','&LOCATION',&NO_OF_STD,'&STA
TUS');
SQL> INSERT INTO STUDENT VALUES('&SID','&SNAME','&SADDR','&COURCE','&DEPT','&CLA
SS','&HNO','&RNO');
SQL> INSERT INTO CHARGES VALUES('&HNO','&RTYPE',&CHARGES);
SQL> INSERT INTO FEES VALUES('&SID','&DATE',&AMOUNT);
Queries
1. Add check constraint to the room type allows the following values only s si
ngle, d -double s -triple, f -four setter.
ALTER TABLE ROOM ADD CONSTRAINTS ROOM1 CHECK(RTYPE IN( S , D , T , F ));
2. Display total number of rooms that are presently vacant.
SQL> SELECT HNAME,CAPACITY FROM HOSTEL,ROOM
2 WHERE ROOM.STATUS='Vacant' AND ROOM.HNO=HOSTEL.HNO;
HNAME CAPACITY
-------------------- ----------
Aramita 300
Shraddha 500
Deval 200
3. Display the number of students of each faculty and dept wise staying in
each hostel.
SQL> SELECT COUNT(SNAME),DEPT,COURCE FROM STUDENT GROUP BY DEPT,COURCE;
COUNT(SNAME) DEPT COURCE
------------ ---------- ----------
1 ASDF MBA
1 Com Sci Aironotic
1 Com Sci Msc
1 Com Sci Science
2 Commerce Mcom
1 POIU Medical
1 QWER MCA
7 rows selected.
4. Display hostels, which have at least 1 single seated room.
SQL> SELECT HNAME FROM HOSTEL,ROOM
2 WHERE 1< (SELECT COUNT(ROOM.RTYPE) FROM ROOM WHERE ROOM.RTYPE LIKE 'S')
3 AND ROOM.HNO=HOSTEL.HNO AND ROOM.RTYPE LIKE 'S';
HNAME
--------------------
Aramita
5. Display the warden name and hostel address of students of computer scien
ce dept.
SQL> SELECT WARDEN,SADDR FROM HOSTEL,STUDENT
2 WHERE STUDENT.DEPT LIKE 'Com Sci' AND STUDENT.HNO=HOSTEL.HNO;
WARDEN SADDR
-------------------- -------------------------
Mehul Karmachari
Mehul Prabhat
Mehul Ankur
6. Display those hostel details where single seated or double seated rooms
are vacant.
SQL> SELECT HNAME FROM HOSTEL,ROOM
2 WHERE RTYPE IN('S','D') AND STATUS='Vacant'
3 AND HOSTEL.HNO=ROOM.HNO;
HNAME
--------------------
Aramita
Shraddha
7. Display detail of hostels occupied by medical student.
SQL> SELECT HNAME FROM HOSTEL,STUDENT
2 WHERE COURCE='Medical' AND HOSTEL.HNO=STUDENT.HNO;
HNAME
--------------------
Shraddha

8. Display hotels, which are totally occupied to its fullest capacity.


SQL> SELECT HNAME FROM HOSTEL,ROOM
2 WHERE ROOM.HNO IN('H1','H2','H3','H4') AND STATUS='Occufied'
3 AND HOSTEL.HNO=ROOM.HNO;
HNAME
--------------------
Shraddha
Deval
9. List details about students who are staying in the double-seated rooms o
f the Shraddha hostel.
SQL> SELECT SNAME FROM STUDENT,ROOM,HOSTEL
2 WHERE RTYPE IN('D') AND HNAME LIKE 'Shraddha'
3 AND STUDENT.HNO=HOSTEL.HNO;
SNAME
--------------------
Pratik
Samir
Darshan
10. Display the total no. Of students staying in each room type of each hos
tel.
SQL> SELECT COUNT(SID),RTYPE,HNAME FROM STUDENT,HOSTEL,ROOM
2 WHERE STUDENT.HNO=ROOM.HNO AND STUDENT.RNO=ROOM.RNO AND HOSTEL.HNO=ROOM.HNO
3 GROUP BY RTYPE,HNAME;
COUNT(SID) R HNAME
---------- - --------------------
4 F Deval
1 S Aramita
3 T Shraddha
11. Display details about students who have paid fees in the month of July-
2008.
SQL> SELECT SNAME FROM STUDENT,FEES
2 WHERE TO_CHAR(FDATE,'MM')='07' AND STUDENT.SID=FEES.SID;
SNAME
--------------------
Pratik
Harsh
Roshan
12. For those hostels where total capacity is more then 300, display detail
s of the students studying in science faculty.
SQL> SELECT HNAME FROM HOSTEL,STUDENT
2 WHERE CAPACITY>=300 AND COURCE='Science'
3 AND HOSTEL.HNO=STUDENT.HNO;
no rows selected
13. Display hostel details where there are atleast 10 vacant rooms.
SQL> SELECT HNAME FROM HOSTEL,ROOM
2 WHERE HOSTEL.HNO=ROOM.HNO
3 GROUP BY HNAME HAVING COUNT(STATUS)>=1;
HNAME
--------------------
Aramita
Deval
Shraddha
14. Display details of students who have still not paid fees.
SQL> SELECT SNAME,SADDR,COURCE,DEPT,CLASS FROM STUDENT,FEES
2 WHERE FAMOUNT=0 AND STUDENT.SID=FEES.SID;
SNAME SADDR COURCE DEPT CLASS
-------------------- ---------------------- ---------- ---------- --------
Pratik Bapunagar MBA ASDF Seco
nd
Harsh Karmachari Science Com Sci Third
Roshan Ranip Mcom Commerce Second
15. Display those hostels where singe-seated room is the costliest.
SQL> SELECT HNAME FROM HOSTEL,CHARGES
2 WHERE HOSTEL.HNO=CHARGES.HNO AND
3 CHARGES=(SELECT MAX(CHARGES) FROM CHARGES WHERE RTYPE='S');
HNAME
--------------------
Sandipani

You might also like