· 8 years ago · May 21, 2018, 12:38 PM
1/*==============================================================*/
2/* DBMS name: Microsoft SQL Server 2008 */
3/* Created on: 07.05.2018 14:20:30 */
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('wiadomosc') and o.name = 'FK_WIADOMOS_RELATIONS_DZIAL')
10alter table wiadomosc
11 drop constraint FK_WIADOMOS_RELATIONS_DZIAL
12go
13
14if exists (select 1
15 from sysobjects
16 where id = object_id('dzial')
17 and type = 'U')
18 drop table dzial
19go
20
21if exists (select 1
22 from sysindexes
23 where id = object_id('wiadomosc')
24 and name = 'Relationship_1_FK'
25 and indid > 0
26 and indid < 255)
27 drop index wiadomosc.Relationship_1_FK
28go
29
30if exists (select 1
31 from sysobjects
32 where id = object_id('wiadomosc')
33 and type = 'U')
34 drop table wiadomosc
35go
36
37/*==============================================================*/
38/* Table: dzial */
39/*==============================================================*/
40create table dzial (
41 id_dzial int not null,
42 nazwa_dzial varchar(50) not null,
43 constraint PK_DZIAL primary key nonclustered (id_dzial)
44)
45go
46
47/*==============================================================*/
48/* Table: wiadomosc */
49/*==============================================================*/
50create table wiadomosc (
51 id_wiadomosc int not null,
52 id_dzial int not null,
53 Imie varchar(50) not null,
54 Nazwisko varchar(50) not null,
55 "E-mail" varchar(50) not null,
56 telefon varchar(50) not null,
57 tresc varchar(500) not null,
58 constraint PK_WIADOMOSC primary key nonclustered (id_wiadomosc)
59)
60go
61
62/*==============================================================*/
63/* Index: Relationship_1_FK */
64/*==============================================================*/
65create index Relationship_1_FK on wiadomosc (
66id_dzial ASC
67)
68go
69
70alter table wiadomosc
71 add constraint FK_WIADOMOS_RELATIONS_DZIAL foreign key (id_dzial)
72 references dzial (id_dzial)
73go