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

INDEX

S. NO. NAME DATE SIGN


CASE STUDY I

HOSPITAL
MANAGEMENT
SYSTEM
EXPERIMENT -5
AIM:

1. Creation of a database and writing SQL Queries to retrieve information


from the Database.
2. To implement Data Definition Language (DDL).
3. To implement Data Manipulation Language (DML).

THEORY:

1) CREATE TABLE: The CREATE TABLE statement is used to create a new


table in a database.
SYNTAX:
CREATE TABLE TABLE_NAME(
COLUMN1 DATATYPE
COLUMN2 DATATYPE
);

2) ALTER TABLE: The ALTER TABLE statement is used to add, delete, or


modify columns in existing table.
The ALTER TABLE statement is also used to add and drop various
constraints on existing table.
SYNTAX:
ALTER TABLE table_name
ADD column_name datatype;

3) DROP TABLE: The SQL DROP TABLE statement is used to remove a


table definition and all data, indexes, triggers, constraints, and
permission specifications for that table.
SYNTAX:
DROP TABLE table_name;

4) TRUNCATE: The SQL TRUNCATE TABLE command is used to delete


complete data from an existing table.
SYNTAX:
TRUNCATE TABLE table_name;
5) COLUMN CONSTRAINTS: Constraints can be specified when the table
is created with the CREATE TABLE statement, or after the table is
created with the ALTER TABLE statement.
The following constraints are commonly used in SQL:

 PRIMARY KEY: A combination of a NOT NULL and UNIQUE.


Uniquely identifies each row in a table
 CHECK: Ensures that all values in a column satisfies a
specific condition.
 UNIQUE: Ensures that all values in a column are different.
 NOT NULL: Ensures that a column cannot have a NULL
value.
 DEFAULT: Sets a default value for a column when no value
is specified.

TABLES

Entity Table:
 Department Table
 Doctor
 Nurse
 Ward
 Test

Relationship Table:

 Takestest
 Treats
 Conduct
1. DEPARTMENT TABLE

CREATION

CREATE TABLE "DEPARTMENT"


( DEPTID NUMBER NOT NULL ,
DEPTNAME VARCHAR2(30) NOT NULL ,
HOD_ID NUMBER,
PRIMARY KEY ("DEPTID") ,
)

INSERTION

INSERT INTO DEPARTMENT VALUES(1004,'DENTIST');

DISPLAY

SELECT * FROM DEPARTMENT


2. DOCTOR TABLE

CREATION

CREATE TABLE DOCTOR


( DOCID NUMBER NOT NULL,
DOC_NAME VARCHAR2(30) NOT NULL,
DEPTID NUMBER,
DESIGNATION VARCHAR2(50),
QUALIFICATION VARCHAR2(50),
ADDRESS VARCHAR2(100),
CONTACT NUMBER,
PRIMARY KEY (DOCID) ,
)

INSERTION

INSERT INTO DOCTOR VALUES(1007,'PAKHI DUDEJA',1004,'SENIOR


DOCTOR','BDS,MDS','SARITA VIHAR - 110033',9988123654)
DISPLAY

SELECT * FROM DOCTOR

3. NURSE TABLE

CREATION

CREATE TABLE NURSE


( NURID NUMBER NOT NULL ,
NUR_NAME VARCHAR2(30) NOT NULL ,
DESIGNATION VARCHAR2(50),
QUALIFICATION VARCHAR2(50),
ADDRESS VARCHAR2(100),
CONTACT NUMBER,
DEPT_ID NUMBER,
PRIMARY KEY (NURID)
)

INSERTION
INSERT INTO NURSE VALUES(1005,'KAMINI SHARMA','JUNIOR
NURSE','BSC','PITAMPURA - 110034',9958435445,1004)

DISPLAY

SELECT * FROM NURSE

4. WARD TABLE

CREATION

CREATE TABLE WARD


( WARDID NUMBER NOT NULL ,
WARDNAME VARCHAR2(20),
CAPACITY NUMBER,
DEPTID NUMBER,
PRIMARY KEY (WARDID),
)
INSERTION

INSERT INTO WARD VALUES(1005,'CHILD CARE',25);

DISPLAY

SELECT * FROM WARD


5. TEST TABLE

CREATION

CREATE TABLE TEST


( TESTID NUMBER NOT NULL ,
T_NAME VARCHAR2(20),
POS_RESULT VARCHAR2(25),
NEG_RESULT VARCHAR2(25),
PRIMARY KEY (TESTID)
)

INSERTION

INSERT INTO TEST VALUES(1001,'COLD','VIRAL INFECTION EXISTS','NO INFECTION');

DISPLAY

SELECT * FROM TEST


RELATIONSHIP TABLES

1. TAKESTEST TABLE

CREATION
CREATE TABLE TAKESTEST
( TESTID NUMBER,
PID NUMBER,
RESULT VARCHAR2(25),
PRIMARY KEY ("PID", "TESTID") ,
FOREIGN KEY ("TESTID") REFERENCES "TEST" ("TESTID"),
FOREIGN KEY ("PID") REFERENCES "PATIENT" ("PID")
);

INSERTION
INSERT INTO TAKESTEST VALUES(1003,209,'POSITIVE');

DISPLAY
SELECT * FROM TAKESTEST
2. TREATS TABLE

CREATION
CREATE TABLE TREATS
( DOCID NUMBER,
P_ID NUMBER,
PRIMARY KEY ("DOCID", "P_ID"),
FOREIGN KEY ("DOCID") REFERENCES "DOCTOR" ("DOCID") ,
FOREIGN KEY ("P_ID") REFERENCES "PATIENT" ("PID")
)

INSERTION
INSERT INTO TREATS VALUES(1003,209)
DISPLAY
SELECT * FROM TREATS

3. CONDUCT TABLE

CREATION
CREATE TABLE CONDUCTS
( DOCID NUMBER,
TESTID NUMBER,
PRIMARY KEY ("DOCID", "TESTID"),
FOREIGN KEY ("DOCID") REFERENCES "DOCTOR" ("DOCID"),
FOREIGN KEY ("TESTID") REFERENCES "TEST" ("TESTID")
);

INSERTION
Adding Foreign Key HOD_ID in DEPARTMENT table
ALTER TABLE DEPARTMENT ADD CONSTRAINT HOD_ID_FK FOREIGN
KEY(HOD_ID) REFERENCES DOCTOR(DOCID)

Adding Foreign Key DEPT_ID in DOCTOR table


ALTER TABLE DOCTOR ADD CONSTRAINT DEPT_ID_FK FOREIGN KEY(DPET_ID)
REFERENCES DEPARTMENT(DEPID)

Adding Foreign Key DEPT_WARD_ID in WARD table


ALTER TABLE DOCTOR ADD CONSTRAINT DEPT_WARD_FK FOREIGN KEY
(DEPTID) REFERENCES DEPARTMENT" (DEPTID)
DATA MANIPULATION LANGUAGE

ALTER COMMAND

UPDATE COMMAND
DELETE COMMAND
BASIC SELECT QUERIES

Retrieve Patient Name and Address whose name contains letter 'i' .

Count number of wards whose capacity is more than 10 but less than 40

Retrieve the number of patients in each ward with the ward id


Retrieve Disease, Patient Name and Age of the patients whose age is
between 20 and 40
DATE FUNCTIONS

System Date

System Time
SQL AGGREGATE FUNCTIONS

1. AVG( ) :

2. COUNT( ) :

3. SUM( ) :
4. MAX( ) :

5. MIN( ) :
SQL STRING FUNCTIONS
1. LENGTH( ) :

2. CONCAT( )

3. LOWER( ) :
4. UPPER( ) :

5. SUBSTR( ) :

6. RTRIM( ) :
COMPLEX SQL QUERIES

1. List the info of doctors of Orthopaedic department


SELECT * FROM DOCTOR WHERE DEPTID IN (SELECT DEPTID FROM
DEPARTMENT WHERE DEPTNAME LIKE 'ORTHOPAEDIC');

2. Find details about the Hod of Dental Department


SELECT * FROM DOCTOR WHERE DOCID = (SELECT HOD_ID FROM
DEPARTMENT WHERE DEPTNAME LIKE 'DENTAL');

3. Find wards with maximum capacity


SELECT * FROM WARD WHERE CAPACITY = (SELECT MAX(CAPACITY)
FROM WARD)

4. List all the patients who are treated by the Doctor whose id is 1001
SELECT * FROM PATIENT WHERE PID IN (SELECT P_ID FROM TREATS
WHERE DOCID = 1001)

5. List all contact numbers of doctors of department Gynaecology

SELECT CONTACT FROM DOCTOR WHERE DEPTID = (SELECT DEPTID


FROM DEPARTMENT WHERE DEPTNAME LIKE 'GYNAECOLOGY')
DISCUSSION
 We discussed the use of DDL and its implementation to create tables
and alter them
 The use of DML is understood to manipulate the data stored in tables
using update insert and other commands
 We understood the creation of relationshi table according to the
cardinality
 We run the examples of simple sql queries to see the results produced in
the views created.

CONCLUSIONS
 We Successfully implemented Hospital Management System using
following commands : CREATE, INSERT, ALTER, UPDATE, DROP, DELETE.
 We successfully run the simple sql queries to retrieve data from the
Hospital Database using SELECT command.
CASE STUDY 2

UNIVERSITY
MANAGEMENT
SYSTEM
EXPERIMENT -6
AIM:

1. Creation of a database.
2. To implement all types of join to retrieve data from database tables.
3. To implement the Date Functions in SQL.
4. To implement the Aggregate functions in SQL.

THEORY:

 SQL JOIN
A JOIN clause is used to combine rows from two or more tables, based
on a related column between them.

Different Types of SQL JOINs

Here are the different types of the JOINs in SQL:

 (INNER) JOIN: Returns records that have matching values in both tables
 LEFT (OUTER) JOIN: Return all records from the left table, and the
matched records from the right table
 RIGHT (OUTER) JOIN: Return all records from the right table, and the
matched records from the left table
 FULL (OUTER) JOIN: Return all records when there is a match in either
left or right table
AGGREGATE FUNCTIONS : SQL aggregate functions return a single
value, calculated from values in a column.

AVG() , SUM(), MAX(), MIN(), COUNT()

TABLES

Entity Table :

 College
 Clg_Contact
 Clg_Department
 Student
 Course
 Faculty
 Progress Report

Relationship Table

 Teaches
1. COLLEGE

2. CLG_CONTACT
3. CLG_DEPARTMENT

4. FACULTY
5. COURSES

6. STUDENT
7. PROGRESS_REPORT

8. TEACHES
PERFORMING JOIN ON THE DEFINED UNIVERSITY DATABASE

1. List details of all the students who are alloted to some department
along with their department details (INNER JOIN)

SELECT * FROM STUDENT INNER JOIN CLG_DEPARTMENT ON


STUDENT.DEPT_ID = CLG_DEPARTMENT.DEPT_ID

2. List all the faculty members of the university along with the
courses id they teach , if they teach any course (LEFT JOIN)

SELECT * FROM FACULTY LEFT JOIN TEACHES ON FACULTY.FAC_ID =


TEACHES.FAC_ID

3. List faculty id , faculty name , course id and course name for all the
faculty members and courses even if the faculty teaches no course
or course is taught by none faculty. (FULL JOIN)
SELECT FACULTY.FAC_ID, FACULTY.FAC_NAME, COURSES.COURSE_ID,
COURSES.COURSE_TITLE FROM (FACULTY FULL JOIN TEACHES ON
FACULTY.FAC_ID = TEACHES.FAC_ID) FULL JOIN COURSES ON
COURSES.COURSE_ID = TEACHES.COURSE_ID;

4. List names and id of faculty with the department name whose hod
they are, if they are. (RIGHT JOIN)

SELECT CLG_DEPARTMENT.DEPT_NAME, CLG_DEPARTMENT.HOD_ID,


FACULTY.FAC_NAME , FACULTY.FAC_ID FROM CLG_DEPARTMENT RIGHT
JOIN FACULTY ON CLG_DEPARTMENT.HOD_ID = FACULTY.FAC_ID
DISCUSSION :
 We discussed how performing different joins, on defined
University Database, data can be retrieved in different ways
showing relation between tables.
 The data could be retrieved from more than one table which gave
view maintaining proper relation between tables.
 We saw that how different joins create different kind of views.
 We implemented the use of aggregate funstions in the tables.
 We implemented date functions which enables to get system
date and time.

CONCLUSION :
 The database for University is implemented successfully.
 The implementation of INNER JOIN, OUTER JOIN (full join, right
join, left join) query to retrieve data from tables is successful
 The implementation of aggregate functions on the database is
completed.
PROBLEM STATEMENT FOR HOSPITAL
MANAGEMENT SYSTEM
1. It will maintain information about all departments like dept – name,
contact number, head of department.
2. It will maintain information about the doctors like name, address,
qualification, specialisation, designation, contact number, department.
3. It will maintain information about the patients like name, sex, age, dob,
admitDate, disease, test results, address, contact number.
4. It will maintain information about the nurses like name, address,
qualification, designation, department.
5. It will maintain information about all the tests that are being done in
hospital like test_name, result, concerned patients and concerned
doctor.
6. It will maintain about all wards in each department like ward_no,
department, ward capacity.

ENITIY RELATIONSHIP DIAGRAM


DESCRIPTION
ASSUMPTIONS :
1. A department may have many doctors but a doctor will work in only one
department.
2. A department may have many names but a nurse will work in only one
department.
3. A department may have multiple contact numbers.

RELATIONSHIP :
1. Department : Doctor (1:N)
2. Department : Ward (1:N)
3. Ward : Patient (1:N)
4. Doctor : Patient (1:N)
5. Test : Doctor (1:N)
6. Nurse : Patient (1:N)
PROBLEM STATEMENT FOR UNIVERSITY
MANAGEMENT SYSTEM
1) Database maintains information about all the departments of
each college in the university like name, contact no,address
2) Maintains info about all depts of each college like Department
name, contact no, Hod
3) Maintains info about all the courses being offered in each
department like course no, course title,year
4) Maintains info about all the facilities for each college like name,
designation, qualification,address, contact no
5) Maintains info about all students like name, year.contact
no,address
6) Maintains info about the progress report of students like year ,
grade, Rank

ENITIY RELATIONSHIP DIAGRAM


DESCRIPTION
ASSUMPTIONS :

1) A college can have more than one contact numbers.


2) A student will be having a progress report for each passed year
3) A lecturer can teach more than one course and also a course
can be taught by one or more lecturers.

IDENTIFICATION OF ENTITIES :

1) College(college_id,college_name,contact_no,address)
2) Department(dept_id,dept_name,contact_no,hod_no)
3) Courses(course_id,course_title,year)
4) Faculty(fac_id,fac_name,designation,qualification,contact_no,a
ddress)
5) Student(std_id,std_name,year,admission_date)
6) Progress_report(report_id,year,grade,rank)

IDENTIFICATION OF RELATIONSHIPS :

1) College : Department (1:N)


2) Department : Faculty (1:N)
3) Faculty : Courses (M:N)
4) Department : Courses(1:N)
5) Department : Student(1:N)
6) Student : Progress_report(1:N)
ENTITY RELATIONSHIP DIAGRAM FOR UNIVERSITY DATABASE

Вам также может понравиться