-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
343 lines (302 loc) · 8.78 KB
/
schema.sql
File metadata and controls
343 lines (302 loc) · 8.78 KB
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
create table Category
(
IdCategory int IDENTITY (1 ,1) not null
constraint Category_pk
primary key nonclustered,
Name nvarchar(256) not null,
Description nvarchar(max)
)
go
create unique index Category_IdCategory_uindex
on Category (IdCategory)
go
create table Company
(
IdCompany int IDENTITY (1 ,1) not null
constraint Company_pk
primary key nonclustered,
Name nvarchar(256) not null,
Nip nvarchar(128) not null,
Address nvarchar(128) not null,
PostCode nvarchar(16) not null,
City nvarchar(128) not null,
Country nvarchar(128) not null,
Email nvarchar(256) not null,
Phone nvarchar(128) not null
)
go
create unique index Company_IdCompany_uindex
on Company (IdCompany)
go
create unique index Company_Nip_uindex
on Company (Nip)
go
create unique index Company_Email_uindex
on Company (Email)
go
create unique index Company_Phone_uindex
on Company (Phone)
go
create table CompanyEmployee
(
IdCompanyEmployee int IDENTITY (1 ,1) not null,
IdCompany int not null
constraint CompanyEmployee_Company_IdCompany_fk
references Company,
FirstName nvarchar(128) not null,
LastName nvarchar(128) not null,
Email nvarchar(128) not null,
Phone nvarchar(128) not null
)
go
create unique index CompanyEmployee_IdCompanyEmployee_uindex
on CompanyEmployee (IdCompanyEmployee)
go
create table Configuration
(
Name nchar(64) not null
constraint Configuration_pk
primary key nonclustered,
Value int not null
)
go
create unique index Configuration_Name_uindex
on Configuration (Name)
go
create table Customer
(
IdCustomer int IDENTITY (1 ,1) not null
constraint Customer_pk
primary key nonclustered,
FirstName nvarchar(128) not null,
LastName nvarchar(128) not null,
Email nvarchar(256) not null,
Phone nvarchar(256) not null,
TotalPaid money not null
)
go
create unique index Customer_IdCustomer_uindex
on Customer (IdCustomer)
go
create unique index Customer_Email_uindex
on Customer (Email)
go
create unique index Customer_Phone_uindex
on Customer (Phone)
go
create table CustomerDiscount
(
IdCustomerDiscount int IDENTITY (1 ,1) not null
constraint CustomerDiscount_pk
primary key nonclustered,
IdCustomer int not null
constraint CustomerDiscount_Customer_IdCustomer_fk
references Customer,
Discount int not null,
Active bit not null,
BeginDate datetime not null,
EndDate datetime not null
)
go
create unique index CustomerDiscount_IdCustomerDiscount_uindex
on CustomerDiscount (IdCustomerDiscount)
go
create table Invoice
(
IdInvoice int IDENTITY (1 ,1) not null
constraint Invoice_pk
primary key nonclustered,
Url nvarchar(256) not null,
IssueDate datetime not null
)
go
create unique index Invoice_IdInvoice_uindex
on Invoice (IdInvoice)
go
create table Menu
(
IdMenu int IDENTITY (1 ,1) not null
constraint Menu_pk
primary key nonclustered,
Day date not null
)
go
create unique index Menu_IdMenu_uindex
on Menu (IdMenu)
go
create table [Order]
(
IdOrder int IDENTITY (1 ,1) not null
constraint Order_pk
primary key nonclustered,
IdCustomer int
constraint Order_Customer_IdCustomer_fk
references Customer,
IdCompany int
constraint Order_Company_IdCompany_fk
references Company,
TotalPrice money not null,
Discount int not null,
Takeaway bit not null,
Prepaid bit not null,
Active bit not null,
PickupDate datetime not null,
CreateDate datetime not null
)
go
create table InvoiceDetail
(
IdInvoiceDetail int IDENTITY (1 ,1) not null
constraint InvoiceDetail_pk
primary key nonclustered,
IdInvoice int not null
constraint InvoiceDetail_Invoice_IdInvoice_fk
references Invoice,
IdOrder int not null
constraint InvoiceDetail_Order_IdOrder_fk
references [Order]
)
go
create unique index InvoiceDetail_IdInvoiceDetail_uindex
on InvoiceDetail (IdInvoiceDetail)
go
create unique index Order_IdOrder_uindex
on [Order] (IdOrder)
go
create table Product
(
IdProduct int IDENTITY (1 ,1) not null
constraint Product_pk
primary key nonclustered,
IdCategory int not null
constraint Product_Category_IdCategory_fk
references Category,
Name nvarchar(256) not null,
Description nvarchar(max),
Active bit not null
)
go
create table MenuDetail
(
IdMenuDetail int IDENTITY (1 ,1) not null
constraint MenuDetail_pk
primary key nonclustered,
IdMenu int not null
constraint MenuDetail_Menu_IdMenu_fk
references Menu
on update cascade on delete cascade,
IdProduct int not null
constraint MenuDetail_Product_IdProduct_fk
references Product,
Price money not null
)
go
create unique index MenuDetail_IdMenuDetail_uindex
on MenuDetail (IdMenuDetail)
go
create table OrderDetail
(
IdOrderDetail int IDENTITY (1 ,1) not null
constraint OrderDetail_pk
primary key nonclustered,
IdOrder int not null
constraint OrderDetail_Order_IdOrder_fk
references [Order]
on update cascade on delete cascade,
IdMenuDetail int not null
constraint OrderDetail_MenuDetail_IdMenuDetail_fk
references MenuDetail,
Quantity smallint not null
)
go
create unique index OrderDetail_IdOrderDetail_uindex
on OrderDetail (IdOrderDetail)
go
create unique index Product_IdProduct_uindex
on Product (IdProduct)
go
create table ReservationStatus
(
IdReservationStatus int IDENTITY (1 ,1) not null
constraint ReservationStatus_pk
primary key nonclustered,
Name nvarchar(256) not null
)
go
create table Reservation
(
IdReservation int IDENTITY (1 ,1) not null
constraint Reservation_pk
primary key nonclustered,
IdCustomer int
constraint Reservation_Customer_IdCustomer_fk
references Customer,
IdCompany int
constraint Reservation_Company_IdCompany_fk
references Company,
IdOrder int
constraint Reservation_Order_IdOrder_fk
references [Order],
IdReservationStatus int not null
constraint Reservation_ReservationStatus_IdReservationStatus_fk
references ReservationStatus,
Amount smallint not null,
BeginDate datetime not null,
EndDate datetime not null
)
go
create unique index Reservation_IdReservation_uindex
on Reservation (IdReservation)
go
create table ReservationCompanyEmployee
(
IdReservationCompanyEmployee int IDENTITY (1 ,1) not null
constraint ReservationCompanyEmployee_pk
primary key nonclustered,
IdReservation int not null
constraint ReservationCompanyEmployee_Reservation_IdReservation_fk
references Reservation,
IdCompanyEmployee int not null
constraint ReservationCompanyEmployee_CompanyEmployee_IdCompanyEmployee_fk
references CompanyEmployee (IdCompanyEmployee)
)
go
create unique index ReservationCompanyEmployee_IdReservationCompanyEmployee_uindex
on ReservationCompanyEmployee (IdReservationCompanyEmployee)
go
create unique index ReservationStatus_IdReservationStatus_uindex
on ReservationStatus (IdReservationStatus)
go
create unique index ReservationStatus_Name_uindex
on ReservationStatus (Name)
go
create table [Table]
(
IdTable int IDENTITY (1 ,1) not null
constraint Table_pk
primary key nonclustered,
Capacity smallint not null
)
go
create unique index Table_IdTable_uindex
on [Table] (IdTable)
go
create table TableBusy
(
IdTableBusy int IDENTITY (1 ,1) not null
constraint TableBusy_pk
primary key nonclustered,
IdTable int not null
constraint TableBusy_Table_IdTable_fk
references [Table],
IdReservation int
constraint TableBusy_Reservation_IdReservation_fk
references Reservation,
Active bit not null,
BeginDate datetime not null,
EndDate datetime not null
)
go
create unique index TableBusy_IdTableBusy_uindex
on TableBusy (IdTableBusy)
go