-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInlandMarinaScript.sql
230 lines (195 loc) · 18.5 KB
/
InlandMarinaScript.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
/***********************************************************************************************
* CPRG214 .NET Web Applications Assignment 1 - Database Script *
* March, 2019 *
* Copy and paste this script into a sql query window in SQL Server Management Studio *
* .\sqlexpress may be exchanged for the instance name of your database *
***********************************************************************************************/
/**************************************** PART 1 CREATE DATABASE ******************************/
USE [master]
GO
/****************************** DROP DATABASE IF EXISTS **************************************/
IF EXISTS(SELECT * FROM Sysdatabases WHERE NAME LIKE 'Marina')
DROP DATABASE InlandMarina
GO
/************************************ CREATE Database ***************************************/
CREATE DATABASE [Marina]
GO
USE [Marina]
Go
/******************************** CREATE DOCK TABLE ****************************************/
CREATE TABLE [dbo].[Dock](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Name] [varchar](50) NOT NULL,
[WaterService] [bit] NOT NULL,
[ElectricalService] [bit] NOT NULL,
CONSTRAINT [PK_Dock] PRIMARY KEY CLUSTERED
(
[ID] ASC
))
GO
/******************************** CREATE SLIP TABLE ****************************************/
CREATE TABLE [dbo].[Slip](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Width] [int] NOT NULL,
[Length] [int] NOT NULL,
[DockID] [int] NOT NULL,
CONSTRAINT [PK_Slip] PRIMARY KEY CLUSTERED
(
[ID] ASC
))
GO
ALTER TABLE [dbo].[Slip] WITH CHECK ADD CONSTRAINT [FK_SlipDock] FOREIGN KEY([DockID])
REFERENCES [dbo].[Dock] ([ID])
GO
ALTER TABLE [dbo].[Slip] CHECK CONSTRAINT [FK_SlipDock]
/******************************** CREATE CUSTOMER TABLE ***********************************/
CREATE TABLE [dbo].[Customer](
[ID] [int] IDENTITY(1,1) NOT NULL,
[FirstName] [varchar](30) NOT NULL,
[LastName] [varchar](30) NOT NULL,
[Phone] [varchar](14) NOT NULL,
[City] [varchar](30) NOT NULL,
CONSTRAINT [PK_Customer] PRIMARY KEY CLUSTERED
(
[ID] ASC
))
GO
/******************************** CREATE LEASE TABLE *************************************/
CREATE TABLE [dbo].[Lease](
[ID] [int] IDENTITY(1000,1) NOT NULL,
[SlipID] [int] NOT NULL,
[CustomerID] [int] NOT NULL
CONSTRAINT [PK_Lease] PRIMARY KEY CLUSTERED
(
[ID] ASC
))
GO
ALTER TABLE [dbo].[Lease] WITH CHECK ADD CONSTRAINT [FK_LeaseCustomer] FOREIGN KEY([CustomerID])
REFERENCES [dbo].[Customer] ([ID])
GO
ALTER TABLE [dbo].[Lease] CHECK CONSTRAINT [FK_LeaseCustomer]
GO
ALTER TABLE [dbo].[Lease] WITH CHECK ADD CONSTRAINT [FK_LeaseSlip] FOREIGN KEY([SlipID])
REFERENCES [dbo].[Slip] ([ID])
GO
ALTER TABLE [dbo].[Lease] CHECK CONSTRAINT [FK_LeaseSlip]
GO
/**************************************** PART 2 INSERT DATA ******************************/
--INSERT INTO DOCK
INSERT INTO Dock([Name], WaterService, ElectricalService) VALUES('Dock A', 1, 1)
INSERT INTO Dock([Name], WaterService, ElectricalService) VALUES('Dock B', 1, 0)
INSERT INTO Dock([Name], WaterService, ElectricalService) VALUES('Dock C', 0, 1)
GO
--INSERT INTO SLIP
-- Dock A slips
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,16,1)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,16,1)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,16,1)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,16,1)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,16,1)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,16,1)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,20,1)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,20,1)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,20,1)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,20,1)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,20,1)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,22,1)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,22,1)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,22,1)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,22,1)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,24,1)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,24,1)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,24,1)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,24,1)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,26,1)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,26,1)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,20,1)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,26,1)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,26,1)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,26,1)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,28,1)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,28,1)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,28,1)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,28,1)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,28,1)
GO
-- Dock B slips
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,18,2)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,18,2)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,18,2)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,18,2)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,18,2)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,18,2)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,20,2)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,20,2)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,20,2)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,22,2)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,22,2)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,22,2)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,22,2)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,24,2)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,24,2)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,24,2)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,24,2)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,28,2)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,28,2)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,28,2)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,30,2)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,30,2)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,30,2)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,30,2)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,30,2)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,32,2)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,32,2)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,32,2)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,32,2)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(8,32,2)
GO
-- Dock C slips
INSERT INTO SLIP(Width, [Length], DockId) VALUES(10,22,3)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(10,22,3)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(10,22,3)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(10,22,3)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(10,22,3)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(10,22,3)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(10,22,3)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(10,22,3)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(10,22,3)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(10,22,3)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(10,24,3)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(10,24,3)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(10,24,3)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(10,24,3)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(10,24,3)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(10,24,3)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(10,24,3)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(10,24,3)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(10,24,3)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(10,24,3)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(12,28,3)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(12,28,3)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(12,28,3)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(12,28,3)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(12,28,3)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(12,28,3)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(12,28,3)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(12,28,3)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(12,28,3)
INSERT INTO SLIP(Width, [Length], DockId) VALUES(12,28,3)
GO
-- INSERT CUSTOMER
INSERT INTO Customer(FirstName,LastName,Phone,City) VALUES('John','Doe','265-555-1212','Phoenix');
INSERT INTO Customer(FirstName,LastName,Phone,City) VALUES('Sara','Williams','403-555-9585','Calgary');
INSERT INTO Customer(FirstName,LastName,Phone,City) VALUES('Ken','Wong','802-555-3214','Kansas City');
GO
-- INSERT LEASE
INSERT INTO Lease(SlipID,CustomerID) VALUES(20,1)
INSERT INTO Lease(SlipID,CustomerID) VALUES(42,2)
INSERT INTO Lease(SlipID,CustomerID) VALUES(88,3)
GO
---EXECUTE TEST SQL STATEMENT
SELECT c.FirstName, c.LastName, s.Length, d.Name
FROM Customer c inner join Lease l on c.ID = l.CustomerID
inner join Slip s on l.SlipID = s.ID
inner join Dock d on s.DockID = d.ID
GO