-
Notifications
You must be signed in to change notification settings - Fork 2
/
HospitalManagement.edmx - Copy.sql
227 lines (197 loc) · 6.18 KB
/
HospitalManagement.edmx - Copy.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure
-- --------------------------------------------------
-- Date Created: 01/19/2017 09:38:12
-- Generated from EDMX file: D:\Junaid\Github\HospitalManagement\HospitalManagement.edmx
-- --------------------------------------------------
SET QUOTED_IDENTIFIER OFF;
GO
USE [HospitalManagement];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO
-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------
IF OBJECT_ID(N'[dbo].[FK_UserPatient]', 'F') IS NOT NULL
ALTER TABLE [dbo].[Patients] DROP CONSTRAINT [FK_UserPatient];
GO
IF OBJECT_ID(N'[dbo].[FK_UserCaregiver]', 'F') IS NOT NULL
ALTER TABLE [dbo].[Caregivers] DROP CONSTRAINT [FK_UserCaregiver];
GO
IF OBJECT_ID(N'[dbo].[FK_UserDoctor]', 'F') IS NOT NULL
ALTER TABLE [dbo].[Doctors] DROP CONSTRAINT [FK_UserDoctor];
GO
IF OBJECT_ID(N'[dbo].[FK_PatientCaregiver]', 'F') IS NOT NULL
ALTER TABLE [dbo].[Caregivers] DROP CONSTRAINT [FK_PatientCaregiver];
GO
IF OBJECT_ID(N'[dbo].[FK_UserRole]', 'F') IS NOT NULL
ALTER TABLE [dbo].[Users] DROP CONSTRAINT [FK_UserRole];
GO
-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------
IF OBJECT_ID(N'[dbo].[Users]', 'U') IS NOT NULL
DROP TABLE [dbo].[Users];
GO
IF OBJECT_ID(N'[dbo].[Patients]', 'U') IS NOT NULL
DROP TABLE [dbo].[Patients];
GO
IF OBJECT_ID(N'[dbo].[Caregivers]', 'U') IS NOT NULL
DROP TABLE [dbo].[Caregivers];
GO
IF OBJECT_ID(N'[dbo].[Doctors]', 'U') IS NOT NULL
DROP TABLE [dbo].[Doctors];
GO
IF OBJECT_ID(N'[dbo].[Roles]', 'U') IS NOT NULL
DROP TABLE [dbo].[Roles];
GO
-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------
-- Creating table 'Users'
CREATE TABLE [dbo].[Users] (
[Id] bigint IDENTITY(1,1) NOT NULL,
[Email] nvarchar(max) NULL,
[Password] nvarchar(max) NULL,
[UserName] nvarchar(max) NULL,
[Age] bigint NULL,
[Gender] nvarchar(max) NULL,
[NRIC] nvarchar(max) NULL,
[Comments] nvarchar(max) NULL,
[Address] nvarchar(max) NULL,
[ContactNo] nvarchar(max) NULL,
[FullName] nvarchar(max) NULL,
[Role_Id] bigint NOT NULL
);
GO
-- Creating table 'Patients'
CREATE TABLE [dbo].[Patients] (
[Id] bigint IDENTITY(1,1) NOT NULL,
[Disease] nvarchar(max) NULL,
[Occupation] nvarchar(max) NULL,
[EntryDate] datetime NULL,
[EntryTime] time NULL,
[User_Id] bigint NOT NULL
);
GO
-- Creating table 'Caregivers'
CREATE TABLE [dbo].[Caregivers] (
[Id] bigint IDENTITY(1,1) NOT NULL,
[User_Id] bigint NOT NULL,
[Patient_Id] bigint NULL
);
GO
-- Creating table 'Doctors'
CREATE TABLE [dbo].[Doctors] (
[Id] bigint IDENTITY(1,1) NOT NULL,
[Designation] nvarchar(max) NULL,
[Specialization] nvarchar(max) NULL,
[User_Id] bigint NOT NULL
);
GO
-- Creating table 'Roles'
CREATE TABLE [dbo].[Roles] (
[Id] bigint IDENTITY(1,1) NOT NULL,
[Name] nvarchar(max) NULL
);
GO
-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------
-- Creating primary key on [Id] in table 'Users'
ALTER TABLE [dbo].[Users]
ADD CONSTRAINT [PK_Users]
PRIMARY KEY CLUSTERED ([Id] ASC);
GO
-- Creating primary key on [Id] in table 'Patients'
ALTER TABLE [dbo].[Patients]
ADD CONSTRAINT [PK_Patients]
PRIMARY KEY CLUSTERED ([Id] ASC);
GO
-- Creating primary key on [Id] in table 'Caregivers'
ALTER TABLE [dbo].[Caregivers]
ADD CONSTRAINT [PK_Caregivers]
PRIMARY KEY CLUSTERED ([Id] ASC);
GO
-- Creating primary key on [Id] in table 'Doctors'
ALTER TABLE [dbo].[Doctors]
ADD CONSTRAINT [PK_Doctors]
PRIMARY KEY CLUSTERED ([Id] ASC);
GO
-- Creating primary key on [Id] in table 'Roles'
ALTER TABLE [dbo].[Roles]
ADD CONSTRAINT [PK_Roles]
PRIMARY KEY CLUSTERED ([Id] ASC);
GO
-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------
-- Creating foreign key on [User_Id] in table 'Patients'
ALTER TABLE [dbo].[Patients]
ADD CONSTRAINT [FK_UserPatient]
FOREIGN KEY ([User_Id])
REFERENCES [dbo].[Users]
([Id])
ON DELETE NO ACTION ON UPDATE NO ACTION;
GO
-- Creating non-clustered index for FOREIGN KEY 'FK_UserPatient'
CREATE INDEX [IX_FK_UserPatient]
ON [dbo].[Patients]
([User_Id]);
GO
-- Creating foreign key on [User_Id] in table 'Caregivers'
ALTER TABLE [dbo].[Caregivers]
ADD CONSTRAINT [FK_UserCaregiver]
FOREIGN KEY ([User_Id])
REFERENCES [dbo].[Users]
([Id])
ON DELETE NO ACTION ON UPDATE NO ACTION;
GO
-- Creating non-clustered index for FOREIGN KEY 'FK_UserCaregiver'
CREATE INDEX [IX_FK_UserCaregiver]
ON [dbo].[Caregivers]
([User_Id]);
GO
-- Creating foreign key on [User_Id] in table 'Doctors'
ALTER TABLE [dbo].[Doctors]
ADD CONSTRAINT [FK_UserDoctor]
FOREIGN KEY ([User_Id])
REFERENCES [dbo].[Users]
([Id])
ON DELETE NO ACTION ON UPDATE NO ACTION;
GO
-- Creating non-clustered index for FOREIGN KEY 'FK_UserDoctor'
CREATE INDEX [IX_FK_UserDoctor]
ON [dbo].[Doctors]
([User_Id]);
GO
-- Creating foreign key on [Patient_Id] in table 'Caregivers'
ALTER TABLE [dbo].[Caregivers]
ADD CONSTRAINT [FK_PatientCaregiver]
FOREIGN KEY ([Patient_Id])
REFERENCES [dbo].[Patients]
([Id])
ON DELETE NO ACTION ON UPDATE NO ACTION;
GO
-- Creating non-clustered index for FOREIGN KEY 'FK_PatientCaregiver'
CREATE INDEX [IX_FK_PatientCaregiver]
ON [dbo].[Caregivers]
([Patient_Id]);
GO
-- Creating foreign key on [Role_Id] in table 'Users'
ALTER TABLE [dbo].[Users]
ADD CONSTRAINT [FK_UserRole]
FOREIGN KEY ([Role_Id])
REFERENCES [dbo].[Roles]
([Id])
ON DELETE NO ACTION ON UPDATE NO ACTION;
GO
-- Creating non-clustered index for FOREIGN KEY 'FK_UserRole'
CREATE INDEX [IX_FK_UserRole]
ON [dbo].[Users]
([Role_Id]);
GO
-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------