· 8 years ago · Jun 18, 2018, 02:30 PM
1/*==============================================================*/
2/* DBMS name: Microsoft SQL Server 2008 */
3/* Created on: 18.06.2018 16:25:54 */
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('egzaminator') and o.name = 'FK_EGZAMINA_RELATIONS_ZALICZEN')
10alter table egzaminator
11 drop constraint FK_EGZAMINA_RELATIONS_ZALICZEN
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('ocena') and o.name = 'FK_OCENA_RELATIONS_ZALICZEN')
17alter table ocena
18 drop constraint FK_OCENA_RELATIONS_ZALICZEN
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('przedmiot') and o.name = 'FK_PRZEDMIO_RELATIONS_ZALICZEN')
24alter table przedmiot
25 drop constraint FK_PRZEDMIO_RELATIONS_ZALICZEN
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('student') and o.name = 'FK_STUDENT_RELATIONS_ZALICZEN')
31alter table student
32 drop constraint FK_STUDENT_RELATIONS_ZALICZEN
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('typ_ocena') and o.name = 'FK_TYP_OCEN_RELATIONS_ZALICZEN')
38alter table typ_ocena
39 drop constraint FK_TYP_OCEN_RELATIONS_ZALICZEN
40go
41
42if exists (select 1
43 from sysindexes
44 where id = object_id('egzaminator')
45 and name = 'Relationship_4_FK'
46 and indid > 0
47 and indid < 255)
48 drop index egzaminator.Relationship_4_FK
49go
50
51if exists (select 1
52 from sysobjects
53 where id = object_id('egzaminator')
54 and type = 'U')
55 drop table egzaminator
56go
57
58if exists (select 1
59 from sysindexes
60 where id = object_id('ocena')
61 and name = 'Relationship_3_FK'
62 and indid > 0
63 and indid < 255)
64 drop index ocena.Relationship_3_FK
65go
66
67if exists (select 1
68 from sysobjects
69 where id = object_id('ocena')
70 and type = 'U')
71 drop table ocena
72go
73
74if exists (select 1
75 from sysindexes
76 where id = object_id('przedmiot')
77 and name = 'Relationship_2_FK'
78 and indid > 0
79 and indid < 255)
80 drop index przedmiot.Relationship_2_FK
81go
82
83if exists (select 1
84 from sysobjects
85 where id = object_id('przedmiot')
86 and type = 'U')
87 drop table przedmiot
88go
89
90if exists (select 1
91 from sysindexes
92 where id = object_id('student')
93 and name = 'Relationship_5_FK'
94 and indid > 0
95 and indid < 255)
96 drop index student.Relationship_5_FK
97go
98
99if exists (select 1
100 from sysobjects
101 where id = object_id('student')
102 and type = 'U')
103 drop table student
104go
105
106if exists (select 1
107 from sysindexes
108 where id = object_id('typ_ocena')
109 and name = 'Relationship_1_FK'
110 and indid > 0
111 and indid < 255)
112 drop index typ_ocena.Relationship_1_FK
113go
114
115if exists (select 1
116 from sysobjects
117 where id = object_id('typ_ocena')
118 and type = 'U')
119 drop table typ_ocena
120go
121
122if exists (select 1
123 from sysobjects
124 where id = object_id('zaliczenie')
125 and type = 'U')
126 drop table zaliczenie
127go
128
129/*==============================================================*/
130/* Table: egzaminator */
131/*==============================================================*/
132create table egzaminator (
133 id_egzaminator int not null,
134 id_zaliczenie int not null,
135 imie_egzaminator varchar(30) not null,
136 nazwisko_egzaminator varchar(30) not null,
137 identyfikator_egzaminator int not null,
138 constraint PK_EGZAMINATOR primary key nonclustered (id_egzaminator)
139)
140go
141
142/*==============================================================*/
143/* Index: Relationship_4_FK */
144/*==============================================================*/
145create index Relationship_4_FK on egzaminator (
146id_zaliczenie ASC
147)
148go
149
150/*==============================================================*/
151/* Table: ocena */
152/*==============================================================*/
153create table ocena (
154 id_ocena int not null,
155 id_zaliczenie int not null,
156 nazwa_ocena varchar(30) not null,
157 constraint PK_OCENA primary key nonclustered (id_ocena)
158)
159go
160
161/*==============================================================*/
162/* Index: Relationship_3_FK */
163/*==============================================================*/
164create index Relationship_3_FK on ocena (
165id_zaliczenie ASC
166)
167go
168
169/*==============================================================*/
170/* Table: przedmiot */
171/*==============================================================*/
172create table przedmiot (
173 id_przedmiot int not null,
174 id_zaliczenie int not null,
175 nazwa_przedmiot varchar(30) not null,
176 constraint PK_PRZEDMIOT primary key nonclustered (id_przedmiot)
177)
178go
179
180/*==============================================================*/
181/* Index: Relationship_2_FK */
182/*==============================================================*/
183create index Relationship_2_FK on przedmiot (
184id_zaliczenie ASC
185)
186go
187
188/*==============================================================*/
189/* Table: student */
190/*==============================================================*/
191create table student (
192 id_student int not null,
193 id_zaliczenie int not null,
194 imie_student varchar(30) not null,
195 nazwisko_student varchar(30) not null,
196 identyfikator_student int not null,
197 constraint PK_STUDENT primary key nonclustered (id_student)
198)
199go
200
201/*==============================================================*/
202/* Index: Relationship_5_FK */
203/*==============================================================*/
204create index Relationship_5_FK on student (
205id_zaliczenie ASC
206)
207go
208
209/*==============================================================*/
210/* Table: typ_ocena */
211/*==============================================================*/
212create table typ_ocena (
213 id_typ int not null,
214 id_zaliczenie int not null,
215 nazwa_typ varchar(30) not null,
216 constraint PK_TYP_OCENA primary key nonclustered (id_typ)
217)
218go
219
220/*==============================================================*/
221/* Index: Relationship_1_FK */
222/*==============================================================*/
223create index Relationship_1_FK on typ_ocena (
224id_zaliczenie ASC
225)
226go
227
228/*==============================================================*/
229/* Table: zaliczenie */
230/*==============================================================*/
231create table zaliczenie (
232 id_zaliczenie int not null,
233 constraint PK_ZALICZENIE primary key nonclustered (id_zaliczenie)
234)
235go
236
237alter table egzaminator
238 add constraint FK_EGZAMINA_RELATIONS_ZALICZEN foreign key (id_zaliczenie)
239 references zaliczenie (id_zaliczenie)
240go
241
242alter table ocena
243 add constraint FK_OCENA_RELATIONS_ZALICZEN foreign key (id_zaliczenie)
244 references zaliczenie (id_zaliczenie)
245go
246
247alter table przedmiot
248 add constraint FK_PRZEDMIO_RELATIONS_ZALICZEN foreign key (id_zaliczenie)
249 references zaliczenie (id_zaliczenie)
250go
251
252alter table student
253 add constraint FK_STUDENT_RELATIONS_ZALICZEN foreign key (id_zaliczenie)
254 references zaliczenie (id_zaliczenie)
255go
256
257alter table typ_ocena
258 add constraint FK_TYP_OCEN_RELATIONS_ZALICZEN foreign key (id_zaliczenie)
259 references zaliczenie (id_zaliczenie)
260go