-
Notifications
You must be signed in to change notification settings - Fork 0
/
all sql codes.sql
353 lines (289 loc) · 8.95 KB
/
all sql codes.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
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
344
345
346
347
348
349
350
351
352
353
If Not Exists(Select * From sys.databases where name='EGM_Otomasyon')
Create Database EGM_Otomasyon
Go
Use EGM_Otomasyon
Go
If Not Exists(Select * From INFORMATION_SCHEMA.TABLES where TABLE_NAME='DaireBaskanliklari')
Create Table DaireBaskanliklari (
DaireId Int Identity Primary Key,
DaireName Nvarchar (100),
DaireAddress Nvarchar(250),
DaireTel Nvarchar(11),
DaireFax Nvarchar(10),
Constraint AN_DaireName Unique (DaireName)
)
Go
If Not Exists(Select * From INFORMATION_SCHEMA.TABLES where TABLE_NAME='Subeler')
Create Table Subeler(
SubeId Int Identity Primary Key,
DaireId Int,
SubeName Nvarchar (100),
SubeAddress Nvarchar(250),
SubeTel Nvarchar(11),
SubeFax Nvarchar(10),
Constraint AN_SubeName Unique (SubeName),
Constraint FK_Subeler_DaireId Foreign Key (DaireId)
References DaireBaskanliklari (DaireId)
)
Go
If Not Exists(Select * From INFORMATION_SCHEMA.TABLES where TABLE_NAME='Burolar')
Create Table Burolar (
BuroId Int Identity Primary Key,
SubeId Int,
BuroName Nvarchar (100),
BuroAddress Nvarchar(250),
BuroTel Nvarchar(11),
BuroFax Nvarchar(10),
Constraint FK_Burolar_SubeId Foreign Key (SubeId)
References Subeler (SubeId)
)
Go
If Not Exists(Select * From INFORMATION_SCHEMA.TABLES where TABLE_NAME='Rutbeler')
Create Table Rutbeler (
RutbeId Int Identity Primary Key,
RutbeName Nvarchar (100)
)
Go
If Not Exists(Select * From INFORMATION_SCHEMA.TABLES where TABLE_NAME='MemurTur')
Create Table MemurTur (
MemurTurId Int Identity Primary Key,
MemurTurName Nvarchar (100)
)
Go
If Not Exists(Select * From INFORMATION_SCHEMA.TABLES where TABLE_NAME='Memurlar')
Create Table Memurlar (
MemurTc Int Identity Primary Key,
BuroId Int,
RutbeId Int,
MemurTurId Int,
MemurName Nvarchar (100),
MemurAddress Nvarchar(250),
MemurTel Nvarchar(11),
MemurGorevB Datetime,
MemurGorevS Datetime,
MemurCinsiyet Nvarchar(20),
Constraint FK_Memurlar_BuroId Foreign Key (BuroId)
References Burolar (BuroId),
Constraint FK_Memurlar_RutbeId Foreign Key (RutbeId)
References Rutbeler (RutbeId),
Constraint FK_Memurlar_MemurTurId Foreign Key (MemurTurId)
References MemurTur (MemurTurId)
)
--https://polisnoktasi.com/emniyet-genel-mudurlugu-rutbeler/
Go
If Not Exists(Select * From INFORMATION_SCHEMA.TABLES where TABLE_NAME='UserTypes')
Create table UserTypes
(
UTypeId Int Identity Primary Key,
TypeName Nvarchar(50) Unique
)
Go
If Not Exists(Select * From INFORMATION_SCHEMA.TABLES where TABLE_NAME='Users')
Create Table Users
(
UTypeId Int,
UserId Int Identity Primary Key,
Password Nvarchar(50) Not Null,
Constraint AN_Users_UserId Unique(UserId),
Constraint FK_Users_UserId Foreign Key(UserId)
References Memurlar(MemurTc),
Constraint FK_Users_UTypeId Foreign Key(UTypeId)
References UserTypes(UTypeId)
)
Go
If Not Exists(Select * From INFORMATION_SCHEMA.TABLES where TABLE_NAME='SucTur')
Create Table SucTur (
SucId Int Identity Primary Key,
SucTurName Nvarchar (100)
)
Go
If Not Exists(Select * From INFORMATION_SCHEMA.TABLES where TABLE_NAME='Kan')
Create Table Kan (
KanDna Int Identity Primary Key,
KanName Nvarchar (50)
)
Go
If Not Exists(Select * From INFORMATION_SCHEMA.TABLES where TABLE_NAME='Supheli')
Create Table Supheli (
SupheliTc Int Identity Primary Key,
SupheliName Nvarchar (100),
SupheliAddress Nvarchar(250),
SupheliTel Nvarchar(11),
SupheliTarihi Datetime,
SupheliYas Datetime,
SupheliCinsiyet bit,
KanDna Int,
Suclumu bit
Constraint FK_Supheli_KanDna Foreign Key (KanDna)
References Kan (KanDna)
)
Go
If Not Exists(Select * From INFORMATION_SCHEMA.TABLES where TABLE_NAME='IfadeTur')
Create Table IfadeTur (
IfadeTurId Int Identity Primary Key,
IfadeTurName Nvarchar (100)
)
Go
If Not Exists(Select * From INFORMATION_SCHEMA.TABLES where TABLE_NAME='IfadesiAlinan')
Create Table IfadesiAlinan (
IfadesiAlinanId Int Identity Primary Key,
IfadesiAlinanName Nvarchar (100),
IfadesiAlinanAddress Nvarchar(250),
IfadesiAlinanTel Nvarchar(11),
IfadesiAlinanYas Datetime,
IfadesiAlinanCinsiyet bit ,
)
Go
If Not Exists(Select * From INFORMATION_SCHEMA.TABLES where TABLE_NAME='IfadeDetaylari')
Create Table IfadeDetaylari (
IfadeId Int Identity Primary Key,
IfadesiAlinanId Int,
SucId Int,
IfadeTurId Int,
BuroId Int,
IfadesiAlinanTarihi Datetime,
IfadeAciklamasi Nvarchar (250),
Constraint FK_IfadesiAlinan_SucId Foreign Key (SucId)
References SucTur (SucId),
Constraint FK_IfadesiAlinan_IfadeTurId Foreign Key (IfadeTurId)
References IfadeTur (IfadeTurId),
Constraint FK_IfadeDetaylari_IfadesiAlinanId Foreign Key (IfadesiAlinanId)
References IfadesiAlinan (IfadesiAlinanId),
Constraint FK_IfadeDetaylari_BuroId Foreign Key (BuroId)
References Burolar (BuroId)
)
Go
If Not Exists(Select * From INFORMATION_SCHEMA.TABLES where TABLE_NAME='Sorgulanan')
Create Table Sorgulanan (
SorgulananId Int Identity Primary Key,
SubeId Int,
SupheliTc Int,
MemurTc Int,
SucId Int,
Constraint FK_Sorgulanan_SupheliTc Foreign Key (SupheliTc)
References Supheli (SupheliTc),
Constraint FK_Sorgulanan_MemurTc Foreign Key (MemurTc)
References Memurlar (MemurTc),
Constraint FK_Sorgulanan_SubeId Foreign Key (SubeId)
References Subeler (SubeId),
Constraint FK_Sorgulanan_SucId Foreign Key (SucId)
References SucTur (SucId),
)
Go
If Not Exists(Select * From INFORMATION_SCHEMA.TABLES where TABLE_NAME='SorguDetaylari')
Create Table SorguDetaylari (
SorguId Int Identity Primary Key,
SorgulananId Int,
SorguMemurDetayý Nvarchar(300),
Constraint FK_SorguDetaylari_SorgulananId Foreign Key (SorgulananId)
References Sorgulanan (SorgulananId)
)
Go
If Not Exists(Select * From INFORMATION_SCHEMA.TABLES where TABLE_NAME='Nezarethaneler')
Create Table Nezarethaneler (
NezarethaneId Int Identity Primary Key,
NezarethaneName Nvarchar(60),
SubeId Int,
Constraint FK_Nezarethaneler_SubeId Foreign Key (SubeId)
References Subeler (SubeId),
)
Go
If Not Exists(Select * From INFORMATION_SCHEMA.TABLES where TABLE_NAME='NezarethaneGirisi')
Create Table NezarethaneGirisi (
GirisId Int Identity Primary Key,
NezarethaneId Int,
SupheliTc Int,
NezarethaneGiris Datetime,
Constraint FK_NezarethaneGirisi_SupheliTc Foreign Key (SupheliTc)
References Supheli (SupheliTc),
Constraint FK_NezarethaneGirisi_NezarethaneId Foreign Key (NezarethaneId)
References Nezarethaneler (NezarethaneId)
)
Go
If Not Exists(Select * From INFORMATION_SCHEMA.TABLES where TABLE_NAME='OlayYeri')
Create Table OlayYeri(
OlayId Int Identity Primary Key,
MemurTc Int,
SubeId Int,
OlayName Nvarchar(100),
OlayTarih Datetime,
OlayAddress Nvarchar(250),
Constraint FK_OlayYeri_MemurTc Foreign Key (MemurTc)
References Memurlar (MemurTc),
Constraint FK_OlayYeri_SubeId Foreign Key (SubeId)
References Subeler (SubeId)
)
Go
If Not Exists(Select * From INFORMATION_SCHEMA.TABLES where TABLE_NAME='OtopsiyeGiden')
Create Table OtopsiyeGiden (
GidenId Int Identity Primary Key,
OlayId Int,
GidenName Nvarchar(50),
GidenParmakizi Nvarchar (20),
KanDna Int,
GidenYas Datetime,
GidenCinsiyet bit,
GidenAciklama Nvarchar(250),
Constraint FK_OtopsiyeGiden_KanDna Foreign Key (KanDna)
References Kan (KanDna),
Constraint FK_OtopsiyeGiden_OlayId Foreign Key (OlayId)
References OlayYeri (OlayId)
)
Go
If Not Exists(Select * From INFORMATION_SCHEMA.TABLES where TABLE_NAME='Otopsi')
Create Table Otopsi (
OtopsiId Int Identity Primary Key,
SupheliTc Int,
GidenId Int,
OtopsiName Nvarchar(50),
OtopsiAciklama Nvarchar(250),
OtopsiSonuc bit,
Constraint FK_Otopsi_SupheliTc Foreign Key (SupheliTc)
References Supheli (SupheliTc),
Constraint FK_Otopsi_GidenId Foreign Key (GidenId)
References OtopsiyeGiden (GidenId)
)
Go
If Not Exists(Select * From INFORMATION_SCHEMA.TABLES where TABLE_NAME='Depolar')
Create Table Depolar (
DepoId Int Identity Primary Key,
SubeId Int,
DepoName Nvarchar(50),
DepoAddres Nvarchar(50),
Constraint FK_Depolar_SubeId Foreign Key (SubeId)
References Subeler (SubeId)
)
Go
If Not Exists(Select * From INFORMATION_SCHEMA.TABLES where TABLE_NAME='Urunler')
Create Table Urunler (
UrunId Int Identity Primary Key,
DepoId Int,
UrunName Nvarchar(50),
UrunTur Nvarchar(50),
UrunAdKg Nvarchar(50),
UrunTarih Datetime,
UrunAddress Nvarchar(100),
Constraint FK_Urunler_DepoId Foreign Key (DepoId)
References Depolar (DepoId)
)
Go
If Not Exists(Select * From INFORMATION_SCHEMA.TABLES where TABLE_NAME='GorevTur')
Create Table GorevTur (
GorevTurId Int Identity Primary Key,
GorevTurName Nvarchar(50),
)
Go
If Not Exists(Select * From INFORMATION_SCHEMA.TABLES where TABLE_NAME='GörevDetaylarý')
Create Table GorevDetaylari (
GorevId Int Identity Primary Key,
GorevTurId Int,
MemurTc Int,
GorevName Nvarchar(50),
GorevTarihi Datetime,
GorevAddres Nvarchar(50),
Constraint FK_GorevDetaylari_GorevTurId Foreign Key (GorevTurId)
References GorevTur (GorevTurId),
Constraint FK_GorevDetaylari_MemurTc Foreign Key (MemurTc)
References Memurlar (MemurTc)
)
Go