-
Notifications
You must be signed in to change notification settings - Fork 1
/
Pill Finder DB.sql
234 lines (221 loc) · 13.7 KB
/
Pill Finder DB.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
228
229
230
231
232
233
234
/*
Friday, February 24, 202312:17:43 PM
User:
Server: HESHAN-KALHARA
Database: PillFinder
Application:
*/
/* To prevent any potential data loss issues, you should review this script in detail before running it outside the context of the database designer.*/
BEGIN TRANSACTION
SET QUOTED_IDENTIFIER ON
SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
COMMIT
BEGIN TRANSACTION
GO
CREATE TABLE dbo.Pharmacy_owner
(
pharmacy_owner_id int NOT NULL,
name varchar(50) NOT NULL,
address varchar(50) NOT NULL,
phone varchar(10) NOT NULL,
email varchar(50) NOT NULL,
nic varchar(12) NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE dbo.Pharmacy_owner ADD CONSTRAINT
PK_Pharmacy_owner PRIMARY KEY CLUSTERED
(
pharmacy_owner_id
) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
ALTER TABLE dbo.Pharmacy_owner SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
select Has_Perms_By_Name(N'dbo.Pharmacy_owner', 'Object', 'ALTER') as ALT_Per, Has_Perms_By_Name(N'dbo.Pharmacy_owner', 'Object', 'VIEW DEFINITION') as View_def_Per, Has_Perms_By_Name(N'dbo.Pharmacy_owner', 'Object', 'CONTROL') as Contr_Per BEGIN TRANSACTION
GO
CREATE TABLE dbo.Province
(
province_id int NOT NULL,
name nchar(10) NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE dbo.Province ADD CONSTRAINT
PK_Province PRIMARY KEY CLUSTERED
(
province_id
) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
ALTER TABLE dbo.Province SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
select Has_Perms_By_Name(N'dbo.Province', 'Object', 'ALTER') as ALT_Per, Has_Perms_By_Name(N'dbo.Province', 'Object', 'VIEW DEFINITION') as View_def_Per, Has_Perms_By_Name(N'dbo.Province', 'Object', 'CONTROL') as Contr_Per BEGIN TRANSACTION
GO
CREATE TABLE dbo.City
(
city_id int NOT NULL,
name varchar(20) NOT NULL,
province_id int NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE dbo.City ADD CONSTRAINT
PK_City PRIMARY KEY CLUSTERED
(
city_id
) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
ALTER TABLE dbo.City ADD CONSTRAINT
FK_City_Province FOREIGN KEY
(
province_id
) REFERENCES dbo.Province
(
province_id
) ON UPDATE NO ACTION
ON DELETE NO ACTION
GO
ALTER TABLE dbo.City SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
select Has_Perms_By_Name(N'dbo.City', 'Object', 'ALTER') as ALT_Per, Has_Perms_By_Name(N'dbo.City', 'Object', 'VIEW DEFINITION') as View_def_Per, Has_Perms_By_Name(N'dbo.City', 'Object', 'CONTROL') as Contr_Per BEGIN TRANSACTION
GO
CREATE TABLE dbo.Medicine
(
medicine_id int NOT NULL,
name varchar(50) NOT NULL,
dosage varchar(10) NULL,
manufacturer varchar(50) NOT NULL,
supplier varchar(50) NOT NULL,
NDC varchar(10) NOT NULL,
expiration_date varchar(10) NOT NULL,
unit_price float(53) NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE dbo.Medicine ADD CONSTRAINT
PK_Medicine PRIMARY KEY CLUSTERED
(
medicine_id
) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
ALTER TABLE dbo.Medicine SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
select Has_Perms_By_Name(N'dbo.Medicine', 'Object', 'ALTER') as ALT_Per, Has_Perms_By_Name(N'dbo.Medicine', 'Object', 'VIEW DEFINITION') as View_def_Per, Has_Perms_By_Name(N'dbo.Medicine', 'Object', 'CONTROL') as Contr_Per BEGIN TRANSACTION
GO
CREATE TABLE dbo.[User]
(
user_id int NOT NULL IDENTITY (1, 1),
name varchar(20) NOT NULL,
email varchar(20) NOT NULL,
NIC varchar(12) NOT NULL,
password varchar(16) NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE dbo.[User] ADD CONSTRAINT
PK_User PRIMARY KEY CLUSTERED
(
user_id
) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
ALTER TABLE dbo.[User] SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
select Has_Perms_By_Name(N'dbo.[User]', 'Object', 'ALTER') as ALT_Per, Has_Perms_By_Name(N'dbo.[User]', 'Object', 'VIEW DEFINITION') as View_def_Per, Has_Perms_By_Name(N'dbo.[User]', 'Object', 'CONTROL') as Contr_Per BEGIN TRANSACTION
GO
CREATE TABLE dbo.Pharmacy
(
pharmacy_id int NOT NULL,
name varchar(50) NOT NULL,
address varchar(50) NOT NULL,
phone varchar(10) NOT NULL,
user_id int NOT NULL,
city_id int NOT NULL,
is_approved bit NOT NULL,
pharmacy_license varchar(20) NOT NULL,
password varchar(12) NOT NULL,
approved_by int NOT NULL,
website varchar(50) NULL,
operating_hours varchar(20) NOT NULL,
owner_id int NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE dbo.Pharmacy ADD CONSTRAINT
PK_Pharmacy PRIMARY KEY CLUSTERED
(
pharmacy_id
) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
ALTER TABLE dbo.Pharmacy ADD CONSTRAINT
FK_Pharmacy_City FOREIGN KEY
(
city_id
) REFERENCES dbo.City
(
city_id
) ON UPDATE NO ACTION
ON DELETE NO ACTION
GO
ALTER TABLE dbo.Pharmacy ADD CONSTRAINT
FK_Pharmacy_User FOREIGN KEY
(
approved_by
) REFERENCES dbo.[User]
(
user_id
) ON UPDATE NO ACTION
ON DELETE NO ACTION
GO
ALTER TABLE dbo.Pharmacy ADD CONSTRAINT
FK_Pharmacy_Pharmacy_owner FOREIGN KEY
(
owner_id
) REFERENCES dbo.Pharmacy_owner
(
pharmacy_owner_id
) ON UPDATE NO ACTION
ON DELETE NO ACTION
GO
DECLARE @v sql_variant
SET @v = N'owner Details'
EXECUTE sp_addextendedproperty N'MS_Description', @v, N'SCHEMA', N'dbo', N'TABLE', N'Pharmacy', N'CONSTRAINT', N'FK_Pharmacy_Pharmacy_owner'
GO
ALTER TABLE dbo.Pharmacy SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
select Has_Perms_By_Name(N'dbo.Pharmacy', 'Object', 'ALTER') as ALT_Per, Has_Perms_By_Name(N'dbo.Pharmacy', 'Object', 'VIEW DEFINITION') as View_def_Per, Has_Perms_By_Name(N'dbo.Pharmacy', 'Object', 'CONTROL') as Contr_Per BEGIN TRANSACTION
GO
CREATE TABLE dbo.Pharmacy_medicine
(
pharmacy_id int NOT NULL,
medicine_id int NOT NULL,
quantity int NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE dbo.Pharmacy_medicine ADD CONSTRAINT
FK_Pharmacy_medicine_Medicine FOREIGN KEY
(
medicine_id
) REFERENCES dbo.Medicine
(
medicine_id
) ON UPDATE NO ACTION
ON DELETE NO ACTION
GO
ALTER TABLE dbo.Pharmacy_medicine ADD CONSTRAINT
FK_Pharmacy_medicine_Pharmacy FOREIGN KEY
(
pharmacy_id
) REFERENCES dbo.Pharmacy
(
pharmacy_id
) ON UPDATE NO ACTION
ON DELETE NO ACTION
GO
ALTER TABLE dbo.Pharmacy_medicine SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
select Has_Perms_By_Name(N'dbo.Pharmacy_medicine', 'Object', 'ALTER') as ALT_Per, Has_Perms_By_Name(N'dbo.Pharmacy_medicine', 'Object', 'VIEW DEFINITION') as View_def_Per, Has_Perms_By_Name(N'dbo.Pharmacy_medicine', 'Object', 'CONTROL') as Contr_Per