Professional Documents
Culture Documents
DBMS PROJECT
On
Submitted by
AQDAS ABRAR
ADITYA SINGH
KARTIKEY SINGH
TARUN PANDEY
RA1711008010284
RA1711008010292
RA1711008010302
RA1711008010262
BACHELOR OF TECHNOLOGY
IN
INFORMATION TECHNOLOGY
OCTOBER 2019
S.NO TITLES
PAGE
1. ER diagram 3-
8
2. DDL/DML 9
3. SQL constraints 10
4. Retrieving data using select 11-
12
5. Restrictions and sorting 13-
14
6. Aggregate and grouping 15-
16
7. Single row function 17-
19
8. Joins
20-22
9. Subquery 23-
24
10. Normalisation 25-
28
(1)ER DIAGRAM
HOSPITAL MANAGEMENT SYSTEM
ALL TABLES OF HOSPITAL MANAGEMENT SYSTEM
SQL> create table patient(p_id int NOT NULL PRIMARY KEY, name varchar(20),address
varchar(20),days_admitted int,contact_no int);
Table created
Table created
SQL> create table employee(e_id int NOT NULL PRIMARY KEY,salary int,e_address varchar(50),sex
varchar(6),n_id int,e_name varchar(50),phone_no int);
Table created
SQL> create table room(p_id int , FOREIGN KEY(p_id) REFERENCES patient(p_id),room_id int NOT NULL
PRIMARY KEY,room_type varchar(40));
Table created
Table created
NAME VARCHAR2(20)
ADDRESS VARCHAR2(20)
DAYS_ADMITTED NUMBER(38)
CONTACT_NO NUMBER(38)
P_ID NUMBER(38)
APPOINTMENT NUMBER(38)
RECORD_NO NUMBER(38)
DECRIPTION VARCHAR2(30)
SALARY NUMBER(38)
E_ADDRESS VARCHAR2(50)
SEX VARCHAR2(6)
N_ID NUMBER(38)
E_NAME VARCHAR2(50)
PHONE_NO NUMBER(38)
P_ID NUMBER(38)
ROOM_TYPE VARCHAR2(40)
SQL> desc medicine;
P_ID NUMBER(38)
CODE NUMBER(38)
QUANTITY NUMBER(38)
PRICE NUMBER(38)
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
RECORD TABLE
SQL> insert into record values(1001,12,32,'Leg_pain');
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
EMPLOYEE TABLE
SQL> insert into employee values(1,10000,'Delhi','male',1,'Arjun',87686);
1 row created.
1 row created.
1 row created.
ROOM TABLE
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
MEDICINE TABLE
SQL> insert into medicine values(1001,1,12,200);
1 row created.
1 row created.
1 row created.
1 row created.
OUTPUT :
Name Null? Type
NAME VARCHAR2(20)
ADDRESS VARCHAR2(20)
DAYS_ADMITTED NUMBER(38)
CONTACT_NO NUMBER(38)
1 row created.
RESULT
1)Create a table name patient and with a attribute p_id which is not null?
SQL>create table patient(p_id int not null);
Table created
2) Create a table name patient and with a attribute p_id which is unique?
SQL>create table patient(p_id int unique);
Table created
3)Create a table name patient and with a attributes p_id which is a primary key?
SQL>create table patient(p_id int primary key);
Table created
4)Create a table name employee and with a attributes e_id which is a foreign
key and name?
SQL>create table employee(e_id int,foreign key(e_id) referances (e_id),name varchar(20));
Table created
5)Create a table name patient and with a attributes address which a default
constraints “KOLKATA”?
SQL>create table patient(p_id int,address varchar(20) default ‘KOLKATA’);
Table created
RESULT
OUTPUT
P_ID ROOM_ID ROOM_TYPE
1001 12 nac
1002 14 ac
1003 15 ac
1006 16 ac
1007 17 nac
1019 18 nac
6 rows selected.
OUTPUT
ROOM_NO
----------
12
14
15
16
17
18
6 rows selected.
3)Display the columns room_id and room_type using concatenation and aliases
room_details of table name course?
SQL>select room_id || room_type as room_details from room;
OUTPUT
ROOM_DETAILS
--------------------------------------------------------------------------------
12nac
14ac
15ac
16ac
17nac
18nac
6 rows selected.
4)Remove the duplicate value from room type from table name room?
SQL>select distinct room_type from room;
OUTPUT
ROOM_TYPE
----------------------------------------
nac
ac
RESULT
1)Display the patient ID and name from table name patient who’s address is
rourkela?
P_ID NAME
---------- --------------------
1006 Zikre
1003 Vishal
2)Display all the data of table employee who’s salary is greater than‘1000’?
SQL> select * from employee where salary>1000;
OUTPUT
1 Arjun 87686
3 Alok 83132
4 Shruti 76232
3)Display all the data of table medicine who’s price range in less then 400?
SQL> select * from medicine where price<400;
OUTPUT :
1001 1 12 200
1002 2 8 203
1003 3 6 290
4)Display the medicine price of table name medicine which in between 200 to
800?
SQL> select * from medicine where price>200 and price<800;
OUTPUT :
1002 2 8 203
1003 3 6 290
1019 5 66 679
RESULT
1)Display the average salary for all the employees in the given table employee?
SQL> select avg(salary)from employee;
OUTPUT :
AVG(SALARY)
-----------
16375
2)Display the minimum and maximum salary in the given table employee?
SQL> select min(salary),max(salary)from employee;
OUTPUT :
MIN(SALARY) MAX(SALARY)
----------- -----------
500 50000
OUTPUT :
COUNT(E_ID)
-----------
OUTPUT :
SUM(PRICE)
----------
2242
RESULT
1)Display the patient ID and patient name and address from patient table where
convert patient name and address into uppercase?
OUTPUT :
9 rows selected.
2)Display the patient ID and patient name and address from patient table where
convert patient name and address into lowercase?
OUTPUT :
9 rows selected.
3)Display the patient ID and address from table patient and change the first
character of all address to uppercase?
OUTPUT :
P_ID INITCAP(ADDRESS)
---------- --------------------
1001 Bby
1002 Hyderabad
1009 Pune
1006 Rourkela
1004 Ranchi
1003 Rourkela
1019 Hyderabad
1005 Pune
1007 Raipur
9 rows selected.
4)Display the patient ID and the length of the name from the table patient use
the character-manipulation function?
SQL> select p_id,name,length(name)from patient;
OUTPUT :
1001 Arunim 6
1002 Steve 5
1009 Rahul 5
1006 Zikre 5
1004 Aqdas 5
1003 Vishal 6
1019 Fardeen 7
1005 Aditya 6
1007 Anuj 4
9 rows selected.
RESULT
1)Display the name from patient table and description from the table record use
inner join?
SQL> select patient.name,record.decription from patient inner join record on patient.p_id = record.p_id;
OUTPUT :
NAME DECRIPTION
-------------------- ------------------------------
Arunim Leg_pain
Steve Headache
Vishal Backache
Aqdas Fever
Aqdas Accident
Aditya Fever
Zikre Cold
Anuj Fever
9 rows selected.
2) Display the appointment from record table and patient first name from the
table patient use left join and order by first name?
SQL>select patient.name,record.appointment from record left join patient on patient.p_id =
record.p_id order by patient.name;
OUTPUT
NAME APPOINTMENT
-------------------- -----------
Aditya 11
Anuj 45
Aqdas 17
Aqdas 15
Arunim 12
Fardeen 78
Steve 14
Vishal 16
Zikre 31
9 rows selected.
3) Display the appointment from record table and patient first name from the
table patient use right join and order by first name?
SQL> select patient.name,record.appointment from record right join patient on patient.p_id =
record.p_id order by patient.name;
OUTPUT :
NAME APPOINTMENT
-------------------- -----------
Aditya 11
Anuj 45
Aqdas 15
Aqdas 17
Arunim 12
Fardeen 78
Rahul
Steve 14
Vishal 16
Zikre 31
10 rows selected.
RESULT
(9) SUBQUERY
1)Display the name of employee where the salary is minimum?
SQL> select e_name from employee where e_id=(select e_id from employee where salary=
(select min(salary) from employee ));
OUTPUT :
E_NAME
--------------------------------------------------
Kartikey
2) Display the employee_id and name of employee where the employee address
is Delhi?
SQL> select e_id,e_name from employee where e_id=(select e_id from employee where
e_address ='Delhi');
OUTPUT :
E_ID E_NAME
---------- --------------------------------------------------
1 Arjun
3)Display the contact number of the patient of who’s days admitted is 78?
SQL> select contact_no from patient where p_id=(select p_id from patient where
days_admitted =78);
OUTPUT :
CONTACT_NO
----------
95621
Appointment
----------------
12
OUTPUT :
3 6 290
4 88 870
RESULT
SUBQUERY all command executed
successfully.
(10) NORMALISATION
(1NF,2NF,3NF)
TABLE ROOM
P_ID ROOM_ID ROOM_TYPE
---------- ---------- ----------------------------------------
1001 12 nac
1002 14 ac
1003 15 ac
1006 16 ac
1007 17 nac
1019 18 nac
TABLE medicine
TABLE patient
TABLE record
RULE
It should be in 1st normal form.
It should not have partial dependencies.
RESULT