· 7 years ago · Dec 17, 2018, 03:42 PM
1/*==============================================================*/
2/* DBMS name: Microsoft SQL Server 2008 */
3/* Created on: 17.12.2018 14:53:31 */
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 Email 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