-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBANK_MP(Skrypt_Tworzacy_PowerDesigner).sql
596 lines (520 loc) · 20.1 KB
/
BANK_MP(Skrypt_Tworzacy_PowerDesigner).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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
/*==============================================================*/
/* DBMS name: Microsoft SQL Server 2008 */
/* Created on: 14.02.2023 21:30:28 */
/*==============================================================*/
if exists (select 1
from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
where r.fkeyid = object_id('Relationship_9') and o.name = 'FK_RELATION_RELATIONS_OFERTA')
alter table Relationship_9
drop constraint FK_RELATION_RELATIONS_OFERTA
go
if exists (select 1
from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
where r.fkeyid = object_id('Relationship_9') and o.name = 'FK_RELATION_RELATIONS_UZYTKOWN')
alter table Relationship_9
drop constraint FK_RELATION_RELATIONS_UZYTKOWN
go
if exists (select 1
from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
where r.fkeyid = object_id('oferta') and o.name = 'FK_OFERTA_RELATIONS_RACHUNKI')
alter table oferta
drop constraint FK_OFERTA_RELATIONS_RACHUNKI
go
if exists (select 1
from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
where r.fkeyid = object_id('oferta') and o.name = 'FK_OFERTA_RELATIONS_KARTY')
alter table oferta
drop constraint FK_OFERTA_RELATIONS_KARTY
go
if exists (select 1
from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
where r.fkeyid = object_id('oferta') and o.name = 'FK_OFERTA_RELATIONS_UBEZPIEC')
alter table oferta
drop constraint FK_OFERTA_RELATIONS_UBEZPIEC
go
if exists (select 1
from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
where r.fkeyid = object_id('oferta') and o.name = 'FK_OFERTA_RELATIONS_KREDYTY')
alter table oferta
drop constraint FK_OFERTA_RELATIONS_KREDYTY
go
if exists (select 1
from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
where r.fkeyid = object_id('oferta') and o.name = 'FK_OFERTA_RELATIONS_OSZCZEDN')
alter table oferta
drop constraint FK_OFERTA_RELATIONS_OSZCZEDN
go
if exists (select 1
from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
where r.fkeyid = object_id('transakcja') and o.name = 'FK_TRANSAKC_RELATIONS_UZYTKOWN')
alter table transakcja
drop constraint FK_TRANSAKC_RELATIONS_UZYTKOWN
go
if exists (select 1
from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
where r.fkeyid = object_id('transakcja') and o.name = 'FK_TRANSAKC_RELATIONS_RODZAJ_T')
alter table transakcja
drop constraint FK_TRANSAKC_RELATIONS_RODZAJ_T
go
if exists (select 1
from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
where r.fkeyid = object_id('transakcja') and o.name = 'FK_TRANSAKC_RELATIONS_PLACOWKA')
alter table transakcja
drop constraint FK_TRANSAKC_RELATIONS_PLACOWKA
go
if exists (select 1
from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
where r.fkeyid = object_id('transakcja') and o.name = 'FK_TRANSAKC_RELATIONS_OPERATOR')
alter table transakcja
drop constraint FK_TRANSAKC_RELATIONS_OPERATOR
go
if exists (select 1
from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
where r.fkeyid = object_id('transakcja') and o.name = 'FK_TRANSAKC_RELATIONS_PRIORYTE')
alter table transakcja
drop constraint FK_TRANSAKC_RELATIONS_PRIORYTE
go
if exists (select 1
from sysindexes
where id = object_id('Relationship_9')
and name = 'Relationship_10_FK'
and indid > 0
and indid < 255)
drop index Relationship_9.Relationship_10_FK
go
if exists (select 1
from sysindexes
where id = object_id('Relationship_9')
and name = 'Relationship_9_FK'
and indid > 0
and indid < 255)
drop index Relationship_9.Relationship_9_FK
go
if exists (select 1
from sysobjects
where id = object_id('Relationship_9')
and type = 'U')
drop table Relationship_9
go
if exists (select 1
from sysobjects
where id = object_id('karty')
and type = 'U')
drop table karty
go
if exists (select 1
from sysobjects
where id = object_id('kredyty')
and type = 'U')
drop table kredyty
go
if exists (select 1
from sysindexes
where id = object_id('oferta')
and name = 'Relationship_12_FK'
and indid > 0
and indid < 255)
drop index oferta.Relationship_12_FK
go
if exists (select 1
from sysindexes
where id = object_id('oferta')
and name = 'Relationship_11_FK'
and indid > 0
and indid < 255)
drop index oferta.Relationship_11_FK
go
if exists (select 1
from sysindexes
where id = object_id('oferta')
and name = 'Relationship_8_FK'
and indid > 0
and indid < 255)
drop index oferta.Relationship_8_FK
go
if exists (select 1
from sysindexes
where id = object_id('oferta')
and name = 'Relationship_7_FK'
and indid > 0
and indid < 255)
drop index oferta.Relationship_7_FK
go
if exists (select 1
from sysindexes
where id = object_id('oferta')
and name = 'Relationship_6_FK'
and indid > 0
and indid < 255)
drop index oferta.Relationship_6_FK
go
if exists (select 1
from sysobjects
where id = object_id('oferta')
and type = 'U')
drop table oferta
go
if exists (select 1
from sysobjects
where id = object_id('operator')
and type = 'U')
drop table operator
go
if exists (select 1
from sysobjects
where id = object_id('oszczednosci')
and type = 'U')
drop table oszczednosci
go
if exists (select 1
from sysobjects
where id = object_id('placowka')
and type = 'U')
drop table placowka
go
if exists (select 1
from sysobjects
where id = object_id('priorytet')
and type = 'U')
drop table priorytet
go
if exists (select 1
from sysobjects
where id = object_id('rachunki')
and type = 'U')
drop table rachunki
go
if exists (select 1
from sysobjects
where id = object_id('rodzaj_transakcji')
and type = 'U')
drop table rodzaj_transakcji
go
if exists (select 1
from sysindexes
where id = object_id('transakcja')
and name = 'Relationship_5_FK'
and indid > 0
and indid < 255)
drop index transakcja.Relationship_5_FK
go
if exists (select 1
from sysindexes
where id = object_id('transakcja')
and name = 'Relationship_4_FK'
and indid > 0
and indid < 255)
drop index transakcja.Relationship_4_FK
go
if exists (select 1
from sysindexes
where id = object_id('transakcja')
and name = 'Relationship_3_FK'
and indid > 0
and indid < 255)
drop index transakcja.Relationship_3_FK
go
if exists (select 1
from sysindexes
where id = object_id('transakcja')
and name = 'Relationship_2_FK'
and indid > 0
and indid < 255)
drop index transakcja.Relationship_2_FK
go
if exists (select 1
from sysindexes
where id = object_id('transakcja')
and name = 'Relationship_1_FK'
and indid > 0
and indid < 255)
drop index transakcja.Relationship_1_FK
go
if exists (select 1
from sysobjects
where id = object_id('transakcja')
and type = 'U')
drop table transakcja
go
if exists (select 1
from sysobjects
where id = object_id('ubezpieczenia')
and type = 'U')
drop table ubezpieczenia
go
if exists (select 1
from sysobjects
where id = object_id('uzytkownik')
and type = 'U')
drop table uzytkownik
go
/*==============================================================*/
/* Table: Relationship_9 */
/*==============================================================*/
create table Relationship_9 (
id_uzytkownik int not null,
id_oferta int not null,
data_zaofertowania datetime null,
constraint PK_RELATIONSHIP_9 primary key (id_uzytkownik, id_oferta)
)
go
/*==============================================================*/
/* Index: Relationship_9_FK */
/*==============================================================*/
create index Relationship_9_FK on Relationship_9 (
id_uzytkownik ASC
)
go
/*==============================================================*/
/* Index: Relationship_10_FK */
/*==============================================================*/
create index Relationship_10_FK on Relationship_9 (
id_oferta ASC
)
go
/*==============================================================*/
/* Table: karty */
/*==============================================================*/
create table karty (
id_karty int identity,
typ_karty varchar(100) not null,
constraint PK_KARTY primary key nonclustered (id_karty)
)
go
/*==============================================================*/
/* Table: kredyty */
/*==============================================================*/
create table kredyty (
id_kredyty int identity,
typ_kredyty varchar(50) not null,
constraint PK_KREDYTY primary key nonclustered (id_kredyty)
)
go
/*==============================================================*/
/* Table: oferta */
/*==============================================================*/
create table oferta (
id_oferta int identity,
id_oszczednosci int null,
id_kredyty int null,
id_ubezpieczenia int null,
id_rachunki int null,
id_karty int null,
constraint PK_OFERTA primary key nonclustered (id_oferta)
)
go
/*==============================================================*/
/* Index: Relationship_6_FK */
/*==============================================================*/
create index Relationship_6_FK on oferta (
id_ubezpieczenia ASC
)
go
/*==============================================================*/
/* Index: Relationship_7_FK */
/*==============================================================*/
create index Relationship_7_FK on oferta (
id_kredyty ASC
)
go
/*==============================================================*/
/* Index: Relationship_8_FK */
/*==============================================================*/
create index Relationship_8_FK on oferta (
id_oszczednosci ASC
)
go
/*==============================================================*/
/* Index: Relationship_11_FK */
/*==============================================================*/
create index Relationship_11_FK on oferta (
id_rachunki ASC
)
go
/*==============================================================*/
/* Index: Relationship_12_FK */
/*==============================================================*/
create index Relationship_12_FK on oferta (
id_karty ASC
)
go
/*==============================================================*/
/* Table: operator */
/*==============================================================*/
create table operator (
id_operator int identity,
nr_operator varchar(10) not null,
constraint PK_OPERATOR primary key nonclustered (id_operator)
)
go
/*==============================================================*/
/* Table: oszczednosci */
/*==============================================================*/
create table oszczednosci (
id_oszczednosci int identity,
typ_oszczednosci varchar(50) not null,
constraint PK_OSZCZEDNOSCI primary key nonclustered (id_oszczednosci)
)
go
/*==============================================================*/
/* Table: placowka */
/*==============================================================*/
create table placowka (
id_placowka int identity,
nazwa_placowka varchar(150) not null,
constraint PK_PLACOWKA primary key nonclustered (id_placowka)
)
go
/*==============================================================*/
/* Table: priorytet */
/*==============================================================*/
create table priorytet (
id_priorytet int identity,
typ_priorytet varchar(50) not null,
constraint PK_PRIORYTET primary key nonclustered (id_priorytet)
)
go
/*==============================================================*/
/* Table: rachunki */
/*==============================================================*/
create table rachunki (
id_rachunki int identity,
typ_rachunki varchar(100) not null,
constraint PK_RACHUNKI primary key nonclustered (id_rachunki)
)
go
/*==============================================================*/
/* Table: rodzaj_transakcji */
/*==============================================================*/
create table rodzaj_transakcji (
id_rodzaj_transakcji int identity,
rodzaj_transakcji varchar(50) not null,
constraint PK_RODZAJ_TRANSAKCJI primary key nonclustered (id_rodzaj_transakcji)
)
go
/*==============================================================*/
/* Table: transakcja */
/*==============================================================*/
create table transakcja (
id_transakcja int identity,
id_operator int not null,
id_rodzaj_transakcji int not null,
id_priorytet int not null,
id_uzytkownik int not null,
id_placowka int not null,
nr_rachunku varchar(26) not null,
data_transakcji datetime not null,
kwota_transakcji varchar(50) not null,
czy_zrealizowano bit not null,
constraint PK_TRANSAKCJA primary key nonclustered (id_transakcja)
)
go
/*==============================================================*/
/* Index: Relationship_1_FK */
/*==============================================================*/
create index Relationship_1_FK on transakcja (
id_uzytkownik ASC
)
go
/*==============================================================*/
/* Index: Relationship_2_FK */
/*==============================================================*/
create index Relationship_2_FK on transakcja (
id_rodzaj_transakcji ASC
)
go
/*==============================================================*/
/* Index: Relationship_3_FK */
/*==============================================================*/
create index Relationship_3_FK on transakcja (
id_placowka ASC
)
go
/*==============================================================*/
/* Index: Relationship_4_FK */
/*==============================================================*/
create index Relationship_4_FK on transakcja (
id_operator ASC
)
go
/*==============================================================*/
/* Index: Relationship_5_FK */
/*==============================================================*/
create index Relationship_5_FK on transakcja (
id_priorytet ASC
)
go
/*==============================================================*/
/* Table: ubezpieczenia */
/*==============================================================*/
create table ubezpieczenia (
id_ubezpieczenia int identity,
typ_ubezpieczenia varchar(50) not null,
constraint PK_UBEZPIECZENIA primary key nonclustered (id_ubezpieczenia)
)
go
/*==============================================================*/
/* Table: uzytkownik */
/*==============================================================*/
create table uzytkownik (
id_uzytkownik int identity,
imie_uzytkownik varchar(50) not null,
nazwisko_uzytkownik varchar(50) not null,
nr_pesel_uzytkownik varchar(11) not null,
nr_telefonu_uzytkownik varchar(12) not null,
adres_1_uzytkownik varchar(150) not null,
adres_2_uzytkownik varchar(50) null,
kod_pocztowy_uzytkownik varchar(6) not null,
miasto_uzytkownik varchar(50) not null,
email_uzytkownik varchar(50) not null,
constraint PK_UZYTKOWNIK primary key nonclustered (id_uzytkownik)
)
go
alter table Relationship_9
add constraint FK_RELATION_RELATIONS_OFERTA foreign key (id_oferta)
references oferta (id_oferta)
go
alter table Relationship_9
add constraint FK_RELATION_RELATIONS_UZYTKOWN foreign key (id_uzytkownik)
references uzytkownik (id_uzytkownik)
go
alter table oferta
add constraint FK_OFERTA_RELATIONS_RACHUNKI foreign key (id_rachunki)
references rachunki (id_rachunki)
go
alter table oferta
add constraint FK_OFERTA_RELATIONS_KARTY foreign key (id_karty)
references karty (id_karty)
go
alter table oferta
add constraint FK_OFERTA_RELATIONS_UBEZPIEC foreign key (id_ubezpieczenia)
references ubezpieczenia (id_ubezpieczenia)
go
alter table oferta
add constraint FK_OFERTA_RELATIONS_KREDYTY foreign key (id_kredyty)
references kredyty (id_kredyty)
go
alter table oferta
add constraint FK_OFERTA_RELATIONS_OSZCZEDN foreign key (id_oszczednosci)
references oszczednosci (id_oszczednosci)
go
alter table transakcja
add constraint FK_TRANSAKC_RELATIONS_UZYTKOWN foreign key (id_uzytkownik)
references uzytkownik (id_uzytkownik)
go
alter table transakcja
add constraint FK_TRANSAKC_RELATIONS_RODZAJ_T foreign key (id_rodzaj_transakcji)
references rodzaj_transakcji (id_rodzaj_transakcji)
go
alter table transakcja
add constraint FK_TRANSAKC_RELATIONS_PLACOWKA foreign key (id_placowka)
references placowka (id_placowka)
go
alter table transakcja
add constraint FK_TRANSAKC_RELATIONS_OPERATOR foreign key (id_operator)
references operator (id_operator)
go
alter table transakcja
add constraint FK_TRANSAKC_RELATIONS_PRIORYTE foreign key (id_priorytet)
references priorytet (id_priorytet)
go