· 7 years ago · Jan 20, 2019, 10:34 AM
1/*==============================================================*/
2/* DBMS name: Microsoft SQL Server 2008 */
3/* Created on: 20.01.2019 11:09:49 */
4/*==============================================================*/
5
6
7if exists (select 1
8 from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
9 where r.fkeyid = object_id('Relationship_4') and o.name = 'FK_RELATION_RELATIONS_ORZESZKI')
10alter table Relationship_4
11 drop constraint FK_RELATION_RELATIONS_ORZESZKI
12go
13
14if exists (select 1
15 from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
16 where r.fkeyid = object_id('Relationship_4') and o.name = 'FK_RELATION_RELATIONS_DYSTRYBU')
17alter table Relationship_4
18 drop constraint FK_RELATION_RELATIONS_DYSTRYBU
19go
20
21if exists (select 1
22 from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
23 where r.fkeyid = object_id('orzeszki_ziemne') and o.name = 'FK_ORZESZKI_RELATIONS_PRODUCEN')
24alter table orzeszki_ziemne
25 drop constraint FK_ORZESZKI_RELATIONS_PRODUCEN
26go
27
28if exists (select 1
29 from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
30 where r.fkeyid = object_id('orzeszki_ziemne') and o.name = 'FK_ORZESZKI_RELATIONS_TYP_OPAK')
31alter table orzeszki_ziemne
32 drop constraint FK_ORZESZKI_RELATIONS_TYP_OPAK
33go
34
35if exists (select 1
36 from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
37 where r.fkeyid = object_id('orzeszki_ziemne') and o.name = 'FK_ORZESZKI_RELATIONS_SMAK')
38alter table orzeszki_ziemne
39 drop constraint FK_ORZESZKI_RELATIONS_SMAK
40go
41
42if exists (select 1
43 from sysindexes
44 where id = object_id('Relationship_4')
45 and name = 'Relationship_5_FK'
46 and indid > 0
47 and indid < 255)
48 drop index Relationship_4.Relationship_5_FK
49go
50
51if exists (select 1
52 from sysindexes
53 where id = object_id('Relationship_4')
54 and name = 'Relationship_4_FK'
55 and indid > 0
56 and indid < 255)
57 drop index Relationship_4.Relationship_4_FK
58go
59
60if exists (select 1
61 from sysobjects
62 where id = object_id('Relationship_4')
63 and type = 'U')
64 drop table Relationship_4
65go
66
67if exists (select 1
68 from sysobjects
69 where id = object_id('dystrybutor')
70 and type = 'U')
71 drop table dystrybutor
72go
73
74if exists (select 1
75 from sysindexes
76 where id = object_id('orzeszki_ziemne')
77 and name = 'Relationship_3_FK'
78 and indid > 0
79 and indid < 255)
80 drop index orzeszki_ziemne.Relationship_3_FK
81go
82
83if exists (select 1
84 from sysindexes
85 where id = object_id('orzeszki_ziemne')
86 and name = 'Relationship_2_FK'
87 and indid > 0
88 and indid < 255)
89 drop index orzeszki_ziemne.Relationship_2_FK
90go
91
92if exists (select 1
93 from sysindexes
94 where id = object_id('orzeszki_ziemne')
95 and name = 'Relationship_1_FK'
96 and indid > 0
97 and indid < 255)
98 drop index orzeszki_ziemne.Relationship_1_FK
99go
100
101if exists (select 1
102 from sysobjects
103 where id = object_id('orzeszki_ziemne')
104 and type = 'U')
105 drop table orzeszki_ziemne
106go
107
108if exists (select 1
109 from sysobjects
110 where id = object_id('producent')
111 and type = 'U')
112 drop table producent
113go
114
115if exists (select 1
116 from sysobjects
117 where id = object_id('smak')
118 and type = 'U')
119 drop table smak
120go
121
122if exists (select 1
123 from sysobjects
124 where id = object_id('typ_opakowania')
125 and type = 'U')
126 drop table typ_opakowania
127go
128
129/*==============================================================*/
130/* Table: Relationship_4 */
131/*==============================================================*/
132create table Relationship_4 (
133 id_orzeszki integer not null,
134 id_dystrybutor integer not null,
135 constraint PK_RELATIONSHIP_4 primary key (id_orzeszki, id_dystrybutor)
136)
137go
138
139/*==============================================================*/
140/* Index: Relationship_4_FK */
141/*==============================================================*/
142create index Relationship_4_FK on Relationship_4 (
143id_orzeszki ASC
144)
145go
146
147/*==============================================================*/
148/* Index: Relationship_5_FK */
149/*==============================================================*/
150create index Relationship_5_FK on Relationship_4 (
151id_dystrybutor ASC
152)
153go
154
155/*==============================================================*/
156/* Table: dystrybutor */
157/*==============================================================*/
158create table dystrybutor (
159 id_dystrybutor integer not null,
160 nazwa_dystrybutor char(64) not null,
161 constraint PK_DYSTRYBUTOR primary key (id_dystrybutor)
162)
163go
164
165/*==============================================================*/
166/* Table: orzeszki_ziemne */
167/*==============================================================*/
168create table orzeszki_ziemne (
169 id_orzeszki integer not null,
170 id_typ_opakowania integer not null,
171 id_producent integer not null,
172 id_smak integer not null,
173 nazwa_produktu char(64) not null,
174 waga_brutto smallint not null,
175 czy_obecnie_w_sprzedazy smallint not null,
176 rodzaj_orzeszkow char(128) not null,
177 constraint PK_ORZESZKI_ZIEMNE primary key (id_orzeszki)
178)
179go
180
181/*==============================================================*/
182/* Index: Relationship_1_FK */
183/*==============================================================*/
184create index Relationship_1_FK on orzeszki_ziemne (
185id_producent ASC
186)
187go
188
189/*==============================================================*/
190/* Index: Relationship_2_FK */
191/*==============================================================*/
192create index Relationship_2_FK on orzeszki_ziemne (
193id_typ_opakowania ASC
194)
195go
196
197/*==============================================================*/
198/* Index: Relationship_3_FK */
199/*==============================================================*/
200create index Relationship_3_FK on orzeszki_ziemne (
201id_smak ASC
202)
203go
204
205/*==============================================================*/
206/* Table: producent */
207/*==============================================================*/
208create table producent (
209 id_producent integer not null,
210 nazwa_producent char(64) not null,
211 constraint PK_PRODUCENT primary key (id_producent)
212)
213go
214
215/*==============================================================*/
216/* Table: smak */
217/*==============================================================*/
218create table smak (
219 id_smak integer not null,
220 nazwa_smak char(64) not null,
221 constraint PK_SMAK primary key (id_smak)
222)
223go
224
225/*==============================================================*/
226/* Table: typ_opakowania */
227/*==============================================================*/
228create table typ_opakowania (
229 id_typ_opakowania integer not null,
230 nazwa_typ_opakowania char(64) not null,
231 constraint PK_TYP_OPAKOWANIA primary key (id_typ_opakowania)
232)
233go
234
235alter table Relationship_4
236 add constraint FK_RELATION_RELATIONS_ORZESZKI foreign key (id_orzeszki)
237 references orzeszki_ziemne (id_orzeszki)
238go
239
240alter table Relationship_4
241 add constraint FK_RELATION_RELATIONS_DYSTRYBU foreign key (id_dystrybutor)
242 references dystrybutor (id_dystrybutor)
243go
244
245alter table orzeszki_ziemne
246 add constraint FK_ORZESZKI_RELATIONS_PRODUCEN foreign key (id_producent)
247 references producent (id_producent)
248go
249
250alter table orzeszki_ziemne
251 add constraint FK_ORZESZKI_RELATIONS_TYP_OPAK foreign key (id_typ_opakowania)
252 references typ_opakowania (id_typ_opakowania)
253go
254
255alter table orzeszki_ziemne
256 add constraint FK_ORZESZKI_RELATIONS_SMAK foreign key (id_smak)
257 references smak (id_smak)
258go