· 6 years ago · May 22, 2019, 12:26 PM
1if (object_id ('serwer_gracz') is not null)
2begin
3 alter table [dbo].[gracz]
4 drop constraint serwer_gracz
5end
6go
7if (object_id ('gra_mapa') is not null)
8begin
9 alter table [dbo].[mapa]
10 drop constraint gra_mapa
11end
12go
13if (object_id ('gra_serwer') is not null)
14begin
15 alter table [dbo].[serwer]
16 drop constraint gra_serwer
17end
18go
19if (object_id ('gracz_przedmiot') is not null)
20begin
21 alter table [dbo].[gracz]
22 drop constraint gracz_przedmiot
23end
24go
25if (object_id ('gracz_przedmioty') is not null)
26begin
27 alter table [dbo].[przedmioty]
28 drop constraint gracz_przedmioty
29end
30go
31if (object_id ('gildia_gracz') is not null)
32begin
33 alter table [dbo].[gracz]
34 drop constraint gildia_gracz
35end
36go
37if (object_id ('gracz_nazwa') is not null)
38begin
39 alter table [dbo].[gracz]
40 drop constraint gracz_nazwa
41end
42go
43if (object_id ('gildia_nazwa') is not null)
44begin
45 alter table [dbo].[gildia]
46 drop constraint gildia_nazwa
47end
48go
49if (object_id ('potwor_przedmioty') is not null)
50begin
51 alter table [dbo].[przedmioty]
52 drop constraint potwor_przedmioty
53end
54go
55if (object_id ('potwor_przedmiot') is not null)
56begin
57 alter table [dbo].[potwor]
58 drop constraint potwor_przedmiot
59end
60go
61if (object_id ('kategorie_przedmioty') is not null)
62begin
63 alter table [dbo].[przedmioty]
64 drop constraint kategorie_przedmioty
65end
66go
67if (object_id ('potwor_nazwa') is not null)
68begin
69 alter table [dbo].[potwor]
70 drop constraint potwor_nazwa
71end
72go
73if (object_id ('teren_potwor') is not null)
74begin
75 alter table [dbo].[teren]
76 drop constraint teren_potwor
77end
78go
79if (object_id ('mapa_teren') is not null)
80begin
81 alter table [dbo].[mapa]
82 drop constraint mapa_teren
83end
84go
85if (object_id ('serwer_gildia') is not null)
86begin
87 alter table [dbo].[gildia]
88 drop constraint serwer_gildia
89end
90go
91-------usuwanie tablic
92drop table if exists gracz
93drop table if exists gildia
94drop table if exists serwer
95drop table if exists przedmioty
96drop table if exists kategorie
97drop table if exists nazwa
98drop table if exists potwor
99drop table if exists teren
100drop table if exists mapa
101drop table if exists gra
102go
103---tworzenie tablic
104create table gracz (
105id_gracz int primary key identity,
106przedmioty int,
107serwer int,
108gildia int
109)
110create table gildia(
111id_gildia int identity primary key,
112serwer int
113)
114create table serwer(
115id_serwer int identity primary key,
116nazwa varchar(20),
117gra varchar,
118)
119create table przedmioty(
120id_przedmiot int identity primary key,
121statystyki varchar(100),
122gracze int,
123potwory int,
124kategoria int
125)
126create table kategorie(
127id_kategori int identity primary key,
128nazwa varchar(20),
129bonus varchar (20)
130)
131create table nazwa(
132id_nazwa int identity primary key,
133nazw varchar(50) not null,
134)
135create table potwor(
136id_potwora int identity primary key,
137info varchar(100),
138przedmioty int
139)
140create table teren(
141id_teren int identity primary key,
142wlasciwosci varchar(100),
143potwory int
144)
145create table mapa(
146id_mapa int identity primary key,
147tereny int,
148gra varchar
149)
150create table gra(
151nazwa varchar primary key
152)
153go
154---relacje
155alter table gracz
156add constraint serwer_gracz foreign key(serwer)
157references serwer(id_serwer)
158alter table mapa
159add constraint gra_mapa foreign key (gra)
160references gra(nazwa)
161alter table serwer
162add constraint gra_serwer foreign key (gra)
163references gra(nazwa)
164alter table mapa
165add constraint mapa_teren foreign key (tereny)
166references teren(id_teren)
167alter table teren
168add constraint teren_potwor foreign key (potwory)
169references potwor(id_potwora)
170alter table potwor
171add constraint potwor_nazwa foreign key(id_potwora)
172references nazwa(id_nazwa)
173alter table potwor
174add constraint potwor_przemiot foreign key(przedmioty)
175references przedmioty(id_przedmiot)
176alter table przedmioty
177add constraint kategorie_przedmioty foreign key(kategoria)
178references kategorie(id_kategori)
179alter table gildia
180add constraint serwer_gildia foreign key(serwer)
181references serwer(id_serwer)
182alter table gildia
183add constraint gildia_nazwa foreign key(id_gildia)
184references nazwa(id_nazwa)
185alter table gracz
186add constraint gildia_gracz foreign key(gildia)
187references gildia(id_gildia)
188alter table gracz
189add constraint gracz_przedmiot foreign key(przedmioty)
190references przedmioty(id_przedmiot)
191alter table gracz
192add constraint gracz_nazwa foreign key (id_gracz)
193references nazwa(id_nazwa)
194alter table przedmioty
195add constraint gracz_przedmioty foreign key(gracze)
196references gracz(id_gracz)
197alter table przedmioty
198add constraint potwor_przedmioty foreign key (potwory)
199references potwor(id_potwora)
200go