· 8 years ago · May 17, 2018, 01:38 PM
1if exists(select 1 from sys.sysforeignkey where role='FK_TRANSAKC_._KLIENCI') then
2 alter table Transakcje
3 delete foreign key "FK_TRANSAKC_._KLIENCI"
4end if;
5
6if exists(select 1 from sys.sysforeignkey where role='FK_TRANSAKC_REFERENCE_POJAZDY') then
7 alter table Transakcje
8 delete foreign key FK_TRANSAKC_REFERENCE_POJAZDY
9end if;
10
11drop index if exists Transakcje."._FK";
12
13drop table if exists Transakcje;
14
15/*==============================================================*/
16/* Table: Transakcje */
17/*==============================================================*/
18create table Transakcje
19(
20 IdTranskacji numeric(10) not null,
21 IdPojazdu numeric(10) null,
22 IdKlienci numeric(10) null,
23 IdKlienta numeric(10) null,
24 "Rodzaj transkacji" char(256) null,
25 "Data transkacji" timestamp null,
26 Wartosc numeric(10) null,
27 IloscSamochodow numeric(10) null,
28 constraint PK_TRANSAKCJE primary key clustered (IdTranskacji)
29);
30
31/*==============================================================*/
32/* Index: "._FK" */
33/*==============================================================*/
34create index "._FK" on Transakcje (
35IdKlienci ASC
36);
37
38alter table Transakcje
39 add constraint "FK_TRANSAKC_._KLIENCI" foreign key (IdKlienci)
40 references Klienci (IdKlienci)
41 on update restrict
42 on delete restrict;
43
44alter table Transakcje
45 add constraint FK_TRANSAKC_REFERENCE_POJAZDY foreign key (IdPojazdu)
46 references Pojazdy (IdPojazdu)
47 on update restrict
48 on delete restrict;
49
50
51
52_________________________________________________________________________________________________________
53
54
55
56drop table if exists Klienci;
57
58/*==============================================================*/
59/* Table: Klienci */
60/*==============================================================*/
61create table Klienci
62(
63 IdKlienci numeric(10) not null,
64 Nazwisko char(256) null,
65 Imie char(256) null,
66 DataUrodzenia timestamp null,
67 Pesel numeric(11) null,
68 NIP numeric(12) null,
69 KodPocztowy char(256) null,
70 constraint PK_KLIENCI primary key clustered (IdKlienci)
71);
72_________________________________________________________________________________________________________
73
74
75if exists(select 1 from sys.sysforeignkey where role='FK_POJAZDY___MARKI') then
76 alter table Pojazdy
77 delete foreign key FK_POJAZDY___MARKI
78end if;
79
80drop index if exists Pojazdy.,_FK;
81
82drop table if exists Pojazdy;
83
84/*==============================================================*/
85/* Table: Pojazdy */
86/*==============================================================*/
87create table Pojazdy
88(
89 IdPojazdu numeric(10) not null,
90 IdMarki numeric(10) null,
91 "Rok produkcji" timestamp null,
92 "Rodzaj paliwa" char(256) null,
93 "Rodzaj pojazdu" char(256) null,
94 Przebieg numeric(10) null,
95 constraint PK_POJAZDY primary key clustered (IdPojazdu)
96);
97
98/*==============================================================*/
99/* Index: ,_FK */
100/*==============================================================*/
101create index ,_FK on Pojazdy (
102
103);
104
105alter table Pojazdy
106 add constraint FK_POJAZDY___MARKI foreign key (IdMarki)
107 references Marki (IdMarki)
108 on update restrict
109 on delete restrict;
110
111
112_________________________________________________________________________________________________________
113
114
115if exists(select 1 from sys.sysforeignkey where role='FK_MARKI_REFERENCE_MODELE') then
116 alter table Marki
117 delete foreign key FK_MARKI_REFERENCE_MODELE
118end if;
119
120drop table if exists Marki;
121
122/*==============================================================*/
123/* Table: Marki */
124/*==============================================================*/
125create table Marki
126(
127 IdMarki numeric(10) not null,
128 IdModelu numeric(10) null,
129 NazwaMarki char(256) null,
130 constraint PK_MARKI primary key clustered (IdMarki)
131);
132
133alter table Marki
134 add constraint FK_MARKI_REFERENCE_MODELE foreign key (IdModelu)
135 references Modele (IdModelu)
136 on update restrict
137 on delete restrict;
138
139
140
141_________________________________________________________________________________________________________
142
143
144drop index if exists Modele."-_FK";
145
146drop table if exists Modele;
147
148/*==============================================================*/
149/* Table: Modele */
150/*==============================================================*/
151create table Modele
152(
153 IdModelu numeric(10) not null,
154 IdMarki numeric(10) null,
155 NazwaModelu char(256) null,
156 constraint PK_MODELE primary key clustered (IdModelu)
157);
158
159/*==============================================================*/
160/* Index: "-_FK" */
161/*==============================================================*/
162create index "-_FK" on Modele (
163
164);