forked from AustinWise/fleet_links
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.sql
More file actions
331 lines (318 loc) · 19.3 KB
/
Copy pathdatabase.sql
File metadata and controls
331 lines (318 loc) · 19.3 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
/****** Object: StoredProcedure [dbo].[DeleteOldFleets] Script Date: 05/02/2009 04:33:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Austin Wise
-- Create date: 2008-03-18
-- Description: Deletes old fleets.
-- =============================================
CREATE PROCEDURE [DeleteOldFleets]
-- Add the parameters for the stored procedure here
@before DateTime
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DELETE FROM Fleets WHERE Added < @before
END
GO
/****** Object: Table [dbo].[Alliances] Script Date: 05/02/2009 04:33:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Alliances](
[ID] [bigint] NOT NULL,
[Name] [nvarchar](50) NOT NULL,
CONSTRAINT [PK_Alliances] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[Hits] Script Date: 05/02/2009 04:33:38 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Hits](
[ID] [uniqueidentifier] NOT NULL,
[Time] [datetime] NOT NULL,
[CorpID] [bigint] NOT NULL,
[CorpName] [nvarchar](50) NOT NULL,
[AllianceID] [bigint] NULL,
[AllianceName] [nvarchar](50) NULL,
[SolarSystem] [nvarchar](20) NOT NULL,
[NearestLocation] [nvarchar](30) NULL,
[CharacterID] [bigint] NOT NULL,
[CharacterName] [nvarchar](20) NOT NULL,
[PageName] [nvarchar](20) NOT NULL,
CONSTRAINT [PK_Hits] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[Fleets] Script Date: 05/02/2009 04:33:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [Fleets](
[ID] [bigint] NOT NULL,
[AllianceID] [bigint] NOT NULL,
[Name] [nvarchar](50) NOT NULL,
[Added] [datetime] NOT NULL,
[DeletePassword] [nchar](28) NOT NULL,
[IsDeleted] [bit] NOT NULL CONSTRAINT [DF_Fleets_IsDelete] DEFAULT ((0)),
CONSTRAINT [PK_Fleets] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: StoredProcedure [dbo].[EnsureAlliance] Script Date: 05/02/2009 04:33:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Austin Wise
-- Create date: 2008-03-15
-- Description: Creates an alliance if it does not already exist.
-- =============================================
CREATE PROCEDURE [EnsureAlliance]
-- Add the parameters for the stored procedure here
@id bigint,
@name nvarchar(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
--make sure that the relationship does not already exist
DECLARE @count int
SELECT @count = COUNT(ID) FROM Alliances WHERE ID = @id
IF @count <> 0
RETURN
INSERT INTO Alliances (ID, Name) VALUES (@id, @name)
END
GO
/****** Object: StoredProcedure [dbo].[GetAlliancesOtherThanMineWithFleets] Script Date: 05/02/2009 04:33:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Austin Wise
-- Create date: 2008-03-15
-- Description:
-- =============================================
CREATE PROCEDURE [GetAlliancesOtherThanMineWithFleets]
-- Add the parameters for the stored procedure here
@myAlliance bigint,
@after DateTime
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT * FROM Alliances WHERE
ID in (SELECT AllianceID FROM Fleets WHERE IsDeleted = 0 AND Added > @after)
AND ID != @myAlliance
END
GO
/****** Object: StoredProcedure [dbo].[GetAllianceCurrentFleets] Script Date: 05/02/2009 04:33:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Austin Wise
-- Create date: 2008-03-15
-- Description:
-- =============================================
CREATE PROCEDURE [GetAllianceCurrentFleets]
-- Add the parameters for the stored procedure here
@allianceId bigint,
@after DateTime
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT ID, AllianceID, Name, Added FROM Fleets
WHERE AllianceID = @allianceId AND Added > @after
AND IsDeleted = 0
ORDER BY Added DESC
END
GO
/****** Object: StoredProcedure [dbo].[DeleteFleet] Script Date: 05/02/2009 04:33:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Austin Wise
-- Create date: 2008-03-18
-- Description: Deletes a fleet
-- =============================================
CREATE PROCEDURE [DeleteFleet]
-- Add the parameters for the stored procedure here
@id bigint,
@password nchar(28)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DELETE FROM Fleets WHERE ID = @id AND DeletePassword = @password
END
GO
/****** Object: StoredProcedure [dbo].[GetFleet] Script Date: 05/02/2009 04:33:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Austin Wise
-- Create date: 2008-03-18
-- Description: Gets a fleet
-- =============================================
CREATE PROCEDURE [GetFleet]
-- Add the parameters for the stored procedure here
@id bigint
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT ID, AllianceID, Name, Added FROM Fleets WHERE ID = @id
END
GO
/****** Object: StoredProcedure [dbo].[CreateFleet] Script Date: 05/02/2009 04:33:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Austin Wise
-- Create date: 2008-03-15
-- Description:
-- =============================================
CREATE PROCEDURE [CreateFleet]
-- Add the parameters for the stored procedure here
@id bigint,
@allianceId bigint,
@name nvarchar(50),
@now DateTime,
@deletePassword nchar(28)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
INSERT INTO Fleets (ID, AllianceID, Name, Added, DeletePassword, IsDeleted) VALUES (@id, @allianceId, @name, @now, @deletePassword, 0)
END
GO
/****** Object: StoredProcedure [dbo].[GetHits] Script Date: 05/02/2009 04:33:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Austin Wise
-- Create date: 2008-04-14
-- Description: Gets some hits
-- =============================================
CREATE PROCEDURE [GetHits]
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT * FROM Hits ORDER BY [Time] DESC
END
GO
/****** Object: StoredProcedure [dbo].[DeleteOldHits] Script Date: 05/02/2009 04:33:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Austin Wise
-- Create date: 2009-02-10
-- Description:
-- =============================================
CREATE PROCEDURE [DeleteOldHits]
-- Add the parameters for the stored procedure here
@before datetime
AS
BEGIN
DELETE FROM Hits WHERE Time < @before
END
GO
/****** Object: StoredProcedure [dbo].[RecordHit] Script Date: 05/02/2009 04:33:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Austin Wise
-- Create date: 2008-04-08
-- Description: Records a hit
-- =============================================
CREATE PROCEDURE [RecordHit]
-- Add the parameters for the stored procedure here
@corpId bigint
,@corpName nvarchar(50)
,@AllianceID bigint
,@AllianceName nvarchar(50)
,@SolarSystem nvarchar(20)
,@NearestLocation nvarchar(30)
,@CharacterID bigint
,@CharacterName nvarchar(20)
,@PageName nvarchar(20)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
INSERT INTO [Main].[dbo].[Hits]
([ID]
,[Time]
,[CorpID]
,[CorpName]
,[AllianceID]
,[AllianceName]
,[SolarSystem]
,[NearestLocation]
,[CharacterID]
,[CharacterName]
,[PageName])
VALUES
(newid()
,GETUTCDATE()
,@CorpID
,@CorpName
,@AllianceID
,@AllianceName
,@SolarSystem
,@NearestLocation
,@CharacterID
,@CharacterName
,@PageName)
END
GO
/****** Object: ForeignKey [FK_Fleets_Alliances] Script Date: 05/02/2009 04:33:36 ******/
ALTER TABLE [Fleets] WITH CHECK ADD CONSTRAINT [FK_Fleets_Alliances] FOREIGN KEY([AllianceID])
REFERENCES [Alliances] ([ID])
GO
ALTER TABLE [Fleets] CHECK CONSTRAINT [FK_Fleets_Alliances]
GO