0% found this document useful (0 votes)
174 views3 pages

Hospital Management System - Scripts

This document contains the SQL script for creating tables and inserting data into a Hospital Management System database. It includes tables for Admin, Doctor, Patient, Schedule, Treatment, Medicine, appointments, and reviews. Primary and foreign keys are defined to link the tables together and maintain relational integrity of the data. Sample data is inserted into each table to populate the database.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
174 views3 pages

Hospital Management System - Scripts

This document contains the SQL script for creating tables and inserting data into a Hospital Management System database. It includes tables for Admin, Doctor, Patient, Schedule, Treatment, Medicine, appointments, and reviews. Primary and foreign keys are defined to link the tables together and maintain relational integrity of the data. Sample data is inserted into each table to populate the database.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

E:\MS - DS\DATABASE SYSTEMS\PROJECT\Hospital Management System_Script.

sql 1
1 ---------------------------------------------------------------------------------------------------- ----------------------
-----------
2 -------------------------------------------- Hospital Managerment System
------------------------------------------------------------
3 ---------------------------------------------------------------------------------------------------- ----------------------
-----------
4
5 --------------------------------------------------------------------
6 -- Group Memebers:
7 -- Javaid Ahmed (21L-7278) - BCS(5F)
8 -- Saad Ather (21L-7289) - BCS(5F)
9 --------------------------------------------------------------------
10
11 create database Hospital_Management_System ;
12 use Hospital_Management_System ;
13
14 create table [Admin] (
15 AdminID varchar(30) NOT NULL,
16 AdminName varchar(30) NOT NULL,
17 Designation varchar(30),
18 EmailID varchar(30) NOT NULL,
19 LoginPass varchar(30) NOT NULL
20 )
21
22 create table [Doctor] (
23 DocID varchar(30) NOT NULL,
24 DocName varchar(30) NOT NULL,
25 Department varchar(30),
26 Designation varchar(30),
27 EmailID varchar(30) NOT NULL,
28 LoginPass varchar(30) NOT NULL
29 )
30
31 create table [Schedule] (
32 SchID varchar(30) NOT NULL,
33 DocID varchar(30),
34 DayInWeek varchar(30),
35 AvailableTimeFrom time,
36 AvailableTimeTo time
37 )
38
39 create table [Treatment] (
40 TreatID varchar(30) NOT NULL,
41 TreatName varchar(30) NOT NULL,
42 TreatPrice float
43 )
44
45 create table [Medicine] (
46 MedID varchar(30) NOT NULL,
47 MedName varchar(30) NOT NULL,
48 TreatID varchar(30)
49 )
50
51 create table [TreatOnPatient] (
52 PatID varchar(30) NOT NULL,
53 DocID varchar(30) NOT NULL,
54 TreatID varchar(30) NOT NULL,
55 AdmitDate date NOT NULL,
56 DischargeDate date NOT NULL,
57 )
58
59 create table [Patient] (
60 PatID varchar(30) NOT NULL,
61 PatName varchar(30) NOT NULL,
62 Age int,
63 Gender char(10),
64 Address varchar(30),
65 EmailID varchar(30) NOT NULL,
66 LoginPass varchar(30) NOT NULL
67 )
68
69 create table [Appointment] (
70 AppID varchar(30) NOT NULL,
71 DocID varchar(30),
72 PatID varchar(30),
73 SchID varchar(30)
74 )
75
76 create table [Review] (
77 PatID varchar(30) NOT NULL,
E:\MS - DS\DATABASE SYSTEMS\PROJECT\Hospital Management System_Script.sql 2
78 DocID varchar(30) NOT NULL,
79 Review int
80 )
81
82 alter table [Admin] add constraint PK_Admin primary key (AdminID);
83 alter table [Doctor] add constraint PK_Doctor primary key (DocID);
84 alter table [Patient] add constraint PK_Patient primary key (PatID);
85 alter table [Schedule] add constraint PK_Schedule primary key (SchID);
86 alter table [Treatment] add constraint PK_Treatment primary key (TreatID);
87 alter table [Medicine] add constraint PK_Medicine primary key (MedID);
88 alter table [TreatOnPatient] add constraint PK_TreatOnPatient primary key (PatID, DocID, TreatID);
89 alter table [Appointment] add constraint PK_Appointment primary key (AppID);
90 alter table [Review] add constraint PK_Review primary key (PatID, DocID);
91
92
93 alter table [Schedule] add constraint FK_Schedule foreign key (DocID) references Doctor(DocID) on update no action;
94 alter table [Medicine] add constraint FK_Medicine foreign key (TreatID) references Treatment(TreatID) on delete no action
on update cascade;
95 alter table [TreatOnPatient] add constraint FK_TreatOnPatient1 foreign key (PatID) references Patient(PatID) on delete no
action on update cascade;
96 alter table [TreatOnPatient] add constraint FK_TreatOnPatient2 foreign key (DocID) references Doctor(DocID) on delete no
action on update cascade;
97 alter table [TreatOnPatient] add constraint FK_TreatOnPatient3 foreign key (TreatID) references Treatment(TreatID) on
delete no action on update cascade;
98 alter table [Appointment] add constraint FK_Appointment1 foreign key (DocID) references Doctor(DocID) on delete set null
on update cascade;
99 alter table [Appointment] add constraint FK_Appointment2 foreign key (PatID) references Patient(PatID) on delete set null
on update cascade;
100 alter table [Appointment] add constraint FK_Appointment3 foreign key (SchID) references Schedule(SchID) on delete set null
on update cascade;
101 alter table [Review] add constraint FK_Review1 foreign key (PatID) references Patient(PatID) on update cascade;
102 alter table [Review] add constraint FK_Review2 foreign key (DocID) references Doctor(DocID) on update cascade;
103
104
105 alter table [Patient] add constraint Check_Gender check(Gender in ('M', 'F'));
106 alter table [Review] add constraint Check_Review check(Review between 1 and 5);
107
108
109 insert into [Admin] values
110 ('A1', 'Ali Namwaz', 'Manager', '[email protected]', 'ali123'),
111 ('A2', 'Nawaz Sharif', 'Deputy Director', '[email protected]', 'patwari123'),
112 ('A3', 'Imran Khan', 'Technician', '[email protected]', 'niazi123'),
113 ('A4', 'Ishaq Dar', 'Helper', '[email protected]', 'dear123')
114
115 insert into [Doctor] values
116 ('D1', 'Shmas khan', 'Urology', 'Professor', '[email protected]', 'shmas123'),
117 ('D2', 'Ali malik', 'Gyne', 'Professor', '[email protected]', 'ali123'),
118 ('D3', 'Umer nameem', 'Peads', 'Professor', '[email protected]', 'umer123'),
119 ('D4', 'Junaid farooq', 'Ortho', 'Assistant Professor', '[email protected]', 'junaid123')
120
121 insert into [Patient] values
122 ('P1', 'Gul Khan', 20, 'M', '123 lahore', '[email protected]', 'gul123'),
123 ('P2', 'Sami Malik', 45, 'M', '123 karachi', '[email protected]', 'sami123'),
124 ('P3', 'Komal Satar', 55, 'F', '345 fsd', '[email protected]', 'komal123'),
125 ('P4', 'Farooq Afzal', 15, 'M', '567 islamabad', '[email protected]', 'fooqi123')
126
127 insert into [Schedule] values
128 ('S1', 'D2', 'Monday', '15:00', '20:00'),
129 ('S2', 'D1', 'Tuesday', '11:00', '18:00'),
130 ('S3', 'D3', 'Wednesday', '09:00', '17:00'),
131 ('S4', 'D4', 'Friday', '09:00', '18:00')
132
133 insert into [Treatment] values
134 ('T1', 'Facture surgery', 20000),
135 ('T2', 'Baby delievry', 45000),
136 ('T3', 'Castration', 25000),
137 ('T4', 'Kids surgery', 60000)
138
139 insert into [Medicine] values
140 ('M1', 'Panadol', 'T2'),
141 ('M2', 'Brufine', 'T3'),
142 ('M3', 'Augomentin', 'T4'),
143 ('M4', 'Leflox', 'T1')
144
145 insert into [TreatOnPatient] values
146 ('P1', 'D2', 'T2', '07-08-2020', '07-08-2020'),
147 ('P2', 'D4', 'T1', '04-09-2021', '03-10-2021'),
148 ('P4', 'D1', 'T3', '02-10-2021', '01-11-2021'),
149 ('P3', 'D3', 'T4', '07-08-2020', '07-12-2021')
150
E:\MS - DS\DATABASE SYSTEMS\PROJECT\Hospital Management System_Script.sql 3
151 insert into [Appointment] values
152 ('A1', 'D4', 'P2', 'S3'),
153 ('A2', 'D3', 'P4', 'S1'),
154 ('A4', 'D2', 'P3', 'S2'),
155 ('A3', 'D1', 'P1', 'S4')
156
157 insert into [Review] values
158 ('P1', 'D2', 5),
159 ('P3', 'D4', 4),
160 ('P2', 'D1', 3),
161 ('P4', 'D3', 3)
162
163
164 select * from [Admin]
165 select * from [Doctor]
166 select * from [Patient]
167 select * from [Schedule]
168 select * from [Medicine]
169 select * from [Treatment]
170 select * from [TreatOnPatient]
171 select * from [Appointment]
172 select * from [Review]
173

You might also like