· 8 years ago · Apr 16, 2018, 01:04 PM
1/*==============================================================*/
2/* DBMS name: Microsoft SQL Server 2008 */
3/* Created on: 16.04.2018 15:02:50 */
4/*==============================================================*/
5
6
7if exists (select 1
8 from sysindexes
9 where id = object_id('Relationship_4')
10 and name = 'Relationship_5_FK'
11 and indid > 0
12 and indid < 255)
13 drop index Relationship_4.Relationship_5_FK
14go
15
16if exists (select 1
17 from sysindexes
18 where id = object_id('Relationship_4')
19 and name = 'Relationship_4_FK'
20 and indid > 0
21 and indid < 255)
22 drop index Relationship_4.Relationship_4_FK
23go
24
25if exists (select 1
26 from sysobjects
27 where id = object_id('Relationship_4')
28 and type = 'U')
29 drop table Relationship_4
30go
31
32if exists (select 1
33 from sysobjects
34 where id = object_id('dzial')
35 and type = 'U')
36 drop table dzial
37go
38
39if exists (select 1
40 from sysindexes
41 where id = object_id('faktura')
42 and name = 'Relationship_3_FK'
43 and indid > 0
44 and indid < 255)
45 drop index faktura.Relationship_3_FK
46go
47
48if exists (select 1
49 from sysobjects
50 where id = object_id('faktura')
51 and type = 'U')
52 drop table faktura
53go
54
55if exists (select 1
56 from sysobjects
57 where id = object_id('filia')
58 and type = 'U')
59 drop table filia
60go
61
62if exists (select 1
63 from sysobjects
64 where id = object_id('forma_platnosci')
65 and type = 'U')
66 drop table forma_platnosci
67go
68
69if exists (select 1
70 from sysobjects
71 where id = object_id('klient')
72 and type = 'U')
73 drop table klient
74go
75
76if exists (select 1
77 from sysindexes
78 where id = object_id('pracownicy')
79 and name = 'Relationship_8_FK'
80 and indid > 0
81 and indid < 255)
82 drop index pracownicy.Relationship_8_FK
83go
84
85if exists (select 1
86 from sysindexes
87 where id = object_id('pracownicy')
88 and name = 'Relationship_7_FK'
89 and indid > 0
90 and indid < 255)
91 drop index pracownicy.Relationship_7_FK
92go
93
94if exists (select 1
95 from sysindexes
96 where id = object_id('pracownicy')
97 and name = 'Relationship_6_FK'
98 and indid > 0
99 and indid < 255)
100 drop index pracownicy.Relationship_6_FK
101go
102
103if exists (select 1
104 from sysobjects
105 where id = object_id('pracownicy')
106 and type = 'U')
107 drop table pracownicy
108go
109
110if exists (select 1
111 from sysobjects
112 where id = object_id('produkt')
113 and type = 'U')
114 drop table produkt
115go
116
117if exists (select 1
118 from sysobjects
119 where id = object_id('stanowisko')
120 and type = 'U')
121 drop table stanowisko
122go
123
124if exists (select 1
125 from sysindexes
126 where id = object_id('zamowienia')
127 and name = 'Relationship_9_FK'
128 and indid > 0
129 and indid < 255)
130 drop index zamowienia.Relationship_9_FK
131go
132
133if exists (select 1
134 from sysindexes
135 where id = object_id('zamowienia')
136 and name = 'Relationship_2_FK'
137 and indid > 0
138 and indid < 255)
139 drop index zamowienia.Relationship_2_FK
140go
141
142if exists (select 1
143 from sysindexes
144 where id = object_id('zamowienia')
145 and name = 'Relationship_1_FK'
146 and indid > 0
147 and indid < 255)
148 drop index zamowienia.Relationship_1_FK
149go
150
151if exists (select 1
152 from sysobjects
153 where id = object_id('zamowienia')
154 and type = 'U')
155 drop table zamowienia
156go
157
158/*==============================================================*/
159/* Table: Relationship_4 */
160/*==============================================================*/
161create table Relationship_4 (
162 id_produkt int not null,
163 id_zamowienia int not null,
164 ilosc int null,
165 constraint PK_RELATIONSHIP_4 primary key nonclustered (id_produkt, id_zamowienia)
166)
167go
168
169/*==============================================================*/
170/* Index: Relationship_4_FK */
171/*==============================================================*/
172create index Relationship_4_FK on Relationship_4 (
173id_produkt ASC
174)
175go
176
177/*==============================================================*/
178/* Index: Relationship_5_FK */
179/*==============================================================*/
180create index Relationship_5_FK on Relationship_4 (
181id_zamowienia ASC
182)
183go
184
185/*==============================================================*/
186/* Table: dzial */
187/*==============================================================*/
188create table dzial (
189 id_dzial int not null,
190 nazwa_dzial varchar(20) not null,
191 constraint PK_DZIAL primary key nonclustered (id_dzial)
192)
193go
194
195/*==============================================================*/
196/* Table: faktura */
197/*==============================================================*/
198create table faktura (
199 id_faktura int not null,
200 id_forma_platnosci int not null,
201 nr_faktury varchar(15) not null,
202 data_wystawienia datetime not null,
203 termin_platnosci datetime not null,
204 constraint PK_FAKTURA primary key nonclustered (id_faktura)
205)
206go
207
208/*==============================================================*/
209/* Index: Relationship_3_FK */
210/*==============================================================*/
211create index Relationship_3_FK on faktura (
212id_forma_platnosci ASC
213)
214go
215
216/*==============================================================*/
217/* Table: filia */
218/*==============================================================*/
219create table filia (
220 id_filia int not null,
221 nazwa_filia varchar(20) not null,
222 constraint PK_FILIA primary key nonclustered (id_filia)
223)
224go
225
226/*==============================================================*/
227/* Table: forma_platnosci */
228/*==============================================================*/
229create table forma_platnosci (
230 id_forma_platnosci int not null,
231 nazwa_formy varchar(20) not null,
232 constraint PK_FORMA_PLATNOSCI primary key nonclustered (id_forma_platnosci)
233)
234go
235
236/*==============================================================*/
237/* Table: klient */
238/*==============================================================*/
239create table klient (
240 id_klient int not null,
241 imie varchar(15) not null,
242 nazwisko varchar(20) not null,
243 adres_1 varchar(30) not null,
244 adres_2 varchar(30) not null,
245 adres_3 varchar(30) not null,
246 constraint PK_KLIENT primary key nonclustered (id_klient)
247)
248go
249
250/*==============================================================*/
251/* Table: pracownicy */
252/*==============================================================*/
253create table pracownicy (
254 id_pracownik int not null,
255 id_stanowisko int not null,
256 id_dzial int not null,
257 id_filia int not null,
258 imie_pracownik varchar(20) not null,
259 nazwisko_pracownik varchar(20) not null,
260 pesel_pracownik varchar(20) not null,
261 constraint PK_PRACOWNICY primary key nonclustered (id_pracownik)
262)
263go
264
265/*==============================================================*/
266/* Index: Relationship_6_FK */
267/*==============================================================*/
268create index Relationship_6_FK on pracownicy (
269id_filia ASC
270)
271go
272
273/*==============================================================*/
274/* Index: Relationship_7_FK */
275/*==============================================================*/
276create index Relationship_7_FK on pracownicy (
277id_dzial ASC
278)
279go
280
281/*==============================================================*/
282/* Index: Relationship_8_FK */
283/*==============================================================*/
284create index Relationship_8_FK on pracownicy (
285id_stanowisko ASC
286)
287go
288
289/*==============================================================*/
290/* Table: produkt */
291/*==============================================================*/
292create table produkt (
293 id_produkt int not null,
294 nazwa_produkt varchar(20) not null,
295 cena_rodukt decimal(8,2) not null,
296 constraint PK_PRODUKT primary key nonclustered (id_produkt)
297)
298go
299
300/*==============================================================*/
301/* Table: stanowisko */
302/*==============================================================*/
303create table stanowisko (
304 id_stanowisko int not null,
305 nazwa_stanowisko varchar(20) not null,
306 constraint PK_STANOWISKO primary key nonclustered (id_stanowisko)
307)
308go
309
310/*==============================================================*/
311/* Table: zamowienia */
312/*==============================================================*/
313create table zamowienia (
314 id_zamowienia int not null,
315 id_pracownik int not null,
316 id_klient int not null,
317 id_faktura int null,
318 nr_zamowienia varchar(6) null,
319 data_przyjecia_zamowienia datetime null,
320 data_realizacji datetime null,
321 constraint PK_ZAMOWIENIA primary key nonclustered (id_zamowienia)
322)
323go
324
325/*==============================================================*/
326/* Index: Relationship_1_FK */
327/*==============================================================*/
328create index Relationship_1_FK on zamowienia (
329id_klient ASC
330)
331go
332
333/*==============================================================*/
334/* Index: Relationship_2_FK */
335/*==============================================================*/
336create index Relationship_2_FK on zamowienia (
337id_faktura ASC
338)
339go
340
341/*==============================================================*/
342/* Index: Relationship_9_FK */
343/*==============================================================*/
344create index Relationship_9_FK on zamowienia (
345id_pracownik ASC
346)
347go