· 6 years ago · Oct 14, 2019, 12:58 PM
1/*==============================================================*/
2/* DBMS name: Microsoft SQL Server 2008 */
3/* Created on: 14.10.2019 14:13:59 */
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('kontakt') and o.name = 'FK_KONTAKT_RELATIONS_GRUPA')
10alter table kontakt
11 drop constraint FK_KONTAKT_RELATIONS_GRUPA
12go
13
14if exists (select 1
15 from sysobjects
16 where id = object_id('grupa')
17 and type = 'U')
18 drop table grupa
19go
20
21if exists (select 1
22 from sysindexes
23 where id = object_id('kontakt')
24 and name = 'Relationship_1_FK'
25 and indid > 0
26 and indid < 255)
27 drop index kontakt.Relationship_1_FK
28go
29
30if exists (select 1
31 from sysobjects
32 where id = object_id('kontakt')
33 and type = 'U')
34 drop table kontakt
35go
36
37/*==============================================================*/
38/* Table: grupa */
39/*==============================================================*/
40create table grupa (
41 Id_grupa int not null,
42 Nazwa_grupa varchar(50) not null,
43 constraint PK_GRUPA primary key nonclustered (Id_grupa)
44)
45go
46
47/*==============================================================*/
48/* Table: kontakt */
49/*==============================================================*/
50create table kontakt (
51 Id_kontakt int not null,
52 Id_grupa int not null,
53 Imie varchar(50) not null,
54 Nazwisko varchar(50) not null,
55 Adres_1 varchar(150) not null,
56 Adres_2 char(6) not null,
57 Adres_3 varchar(100) not null,
58 Telefon varchar(20) null,
59 Mobile varchar(20) not null,
60 Email varchar(100) not null,
61 constraint PK_KONTAKT primary key nonclustered (Id_kontakt)
62)
63go
64
65/*==============================================================*/
66/* Index: Relationship_1_FK */
67/*==============================================================*/
68create index Relationship_1_FK on kontakt (
69Id_grupa ASC
70)
71go
72
73alter table kontakt
74 add constraint FK_KONTAKT_RELATIONS_GRUPA foreign key (Id_grupa)
75 references grupa (Id_grupa)
76go