/*==============================================================*/
/* DBMS name:      Microsoft SQL Server 2008                    */
/* Created on:     2/12/2017 11:57:36 PM                        */
/*==============================================================*/


if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('AUTOR') and o.name = 'FK_AUTOR_AUTOR_POZORISN')
alter table AUTOR
   drop constraint FK_AUTOR_AUTOR_POZORISN
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('AUTOR') and o.name = 'FK_AUTOR_AUTOR2_LICE')
alter table AUTOR
   drop constraint FK_AUTOR_AUTOR2_LICE
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('LICE') and o.name = 'FK_LICE_BORAVI_MESTO')
alter table LICE
   drop constraint FK_LICE_BORAVI_MESTO
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('LICE_U_ULOZI_PREDST_PROJ') and o.name = 'FK_LICE_U_U_LICE_ULOG_LICE')
alter table LICE_U_ULOZI_PREDST_PROJ
   drop constraint FK_LICE_U_U_LICE_ULOG_LICE
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('LICE_U_ULOZI_PREDST_PROJ') and o.name = 'FK_LICE_U_U_LICE_U_UL_P_D_ULOG')
alter table LICE_U_ULOZI_PREDST_PROJ
   drop constraint FK_LICE_U_U_LICE_U_UL_P_D_ULOG
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('MESTO') and o.name = 'FK_MESTO_PRIPADA_ZEMLJA')
alter table MESTO
   drop constraint FK_MESTO_PRIPADA_ZEMLJA
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('POZORISNO_DELO') and o.name = 'FK_POZORISN_ZANR_P_D_ZANR')
alter table POZORISNO_DELO
   drop constraint FK_POZORISN_ZANR_P_D_ZANR
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('POZORISTE') and o.name = 'FK_POZORIST_RADI_MESTO')
alter table POZORISTE
   drop constraint FK_POZORIST_RADI_MESTO
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('POZ_PREDST') and o.name = 'FK_POZ_PRED_POZ_PREDS_POZORIST')
alter table POZ_PREDST
   drop constraint FK_POZ_PRED_POZ_PREDS_POZORIST
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('POZ_PREDST') and o.name = 'FK_POZ_PRED_POZ_PREDS_PREDSTAV')
alter table POZ_PREDST
   drop constraint FK_POZ_PRED_POZ_PREDS_PREDSTAV
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('PREDSTAVA_NA_REPERTOARU') and o.name = 'FK_PREDSTAV_PREDSTAVA_PREDSTAV')
alter table PREDSTAVA_NA_REPERTOARU
   drop constraint FK_PREDSTAV_PREDSTAVA_PREDSTAV
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('PREDSTAVA_NA_REPERTOARU') and o.name = 'FK_PREDSTAV_PREDSTAVA_PROSTORI')
alter table PREDSTAVA_NA_REPERTOARU
   drop constraint FK_PREDSTAV_PREDSTAVA_PROSTORI
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('PREVODILAC') and o.name = 'FK_PREVODIL_PREVODILA_POZORISN')
alter table PREVODILAC
   drop constraint FK_PREVODIL_PREVODILA_POZORISN
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('PREVODILAC') and o.name = 'FK_PREVODIL_PREVODILA_LICE')
alter table PREVODILAC
   drop constraint FK_PREVODIL_PREVODILA_LICE
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('PROSTORIJA') and o.name = 'FK_PROSTORI_PROSTORIJ_POZORIST')
alter table PROSTORIJA
   drop constraint FK_PROSTORI_PROSTORIJ_POZORIST
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('P_D_PREDST') and o.name = 'FK_P_D_PRED_P_D_PREDS_POZORISN')
alter table P_D_PREDST
   drop constraint FK_P_D_PRED_P_D_PREDS_POZORISN
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('P_D_PREDST') and o.name = 'FK_P_D_PRED_P_D_PREDS_PREDSTAV')
alter table P_D_PREDST
   drop constraint FK_P_D_PRED_P_D_PREDS_PREDSTAV
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('P_D_ULOGA') and o.name = 'FK_P_D_ULOG_P_D_ULOGA_ULOGA')
alter table P_D_ULOGA
   drop constraint FK_P_D_ULOG_P_D_ULOGA_ULOGA
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('P_D_ULOGA') and o.name = 'FK_P_D_ULOG_P_D_ULOGA_POZORISN')
alter table P_D_ULOGA
   drop constraint FK_P_D_ULOG_P_D_ULOGA_POZORISN
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('UCESTVUJE_U_PREDSTAVI') and o.name = 'FK_UCESTVUJ_UCESTVUJE_LICE_U_U')
alter table UCESTVUJE_U_PREDSTAVI
   drop constraint FK_UCESTVUJ_UCESTVUJE_LICE_U_U
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('UCESTVUJE_U_PREDSTAVI') and o.name = 'FK_UCESTVUJ_UCESTVUJE_PREDSTAV')
alter table UCESTVUJE_U_PREDSTAVI
   drop constraint FK_UCESTVUJ_UCESTVUJE_PREDSTAV
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('AUTOR')
            and   name  = 'AUTOR_FK'
            and   indid > 0
            and   indid < 255)
   drop index AUTOR.AUTOR_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('AUTOR')
            and   name  = 'AUTOR2_FK'
            and   indid > 0
            and   indid < 255)
   drop index AUTOR.AUTOR2_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('AUTOR')
            and   type = 'U')
   drop table AUTOR
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('LICE')
            and   name  = 'BORAVI_FK'
            and   indid > 0
            and   indid < 255)
   drop index LICE.BORAVI_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('LICE')
            and   type = 'U')
   drop table LICE
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('LICE_U_ULOZI_PREDST_PROJ')
            and   name  = 'LICE_U_ULOZI_P_D_FK'
            and   indid > 0
            and   indid < 255)
   drop index LICE_U_ULOZI_PREDST_PROJ.LICE_U_ULOZI_P_D_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('LICE_U_ULOZI_PREDST_PROJ')
            and   name  = 'LICE_ULOGA_P_P_FK'
            and   indid > 0
            and   indid < 255)
   drop index LICE_U_ULOZI_PREDST_PROJ.LICE_ULOGA_P_P_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('LICE_U_ULOZI_PREDST_PROJ')
            and   type = 'U')
   drop table LICE_U_ULOZI_PREDST_PROJ
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('MESTO')
            and   name  = 'PRIPADA_FK'
            and   indid > 0
            and   indid < 255)
   drop index MESTO.PRIPADA_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('MESTO')
            and   type = 'U')
   drop table MESTO
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('POZORISNO_DELO')
            and   name  = 'ZANR_P_D_FK'
            and   indid > 0
            and   indid < 255)
   drop index POZORISNO_DELO.ZANR_P_D_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('POZORISNO_DELO')
            and   type = 'U')
   drop table POZORISNO_DELO
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('POZORISTE')
            and   name  = 'RADI_FK'
            and   indid > 0
            and   indid < 255)
   drop index POZORISTE.RADI_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('POZORISTE')
            and   type = 'U')
   drop table POZORISTE
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('POZ_PREDST')
            and   name  = 'POZ_PREDST_FK'
            and   indid > 0
            and   indid < 255)
   drop index POZ_PREDST.POZ_PREDST_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('POZ_PREDST')
            and   name  = 'POZ_PREDST2_FK'
            and   indid > 0
            and   indid < 255)
   drop index POZ_PREDST.POZ_PREDST2_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('POZ_PREDST')
            and   type = 'U')
   drop table POZ_PREDST
go

if exists (select 1
            from  sysobjects
           where  id = object_id('PREDSTAVA')
            and   type = 'U')
   drop table PREDSTAVA
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('PREDSTAVA_NA_REPERTOARU')
            and   name  = 'PREDSTAVA_NA_REPERTOARU_FK'
            and   indid > 0
            and   indid < 255)
   drop index PREDSTAVA_NA_REPERTOARU.PREDSTAVA_NA_REPERTOARU_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('PREDSTAVA_NA_REPERTOARU')
            and   name  = 'PREDSTAVA_U_PROSTORIJI_FK'
            and   indid > 0
            and   indid < 255)
   drop index PREDSTAVA_NA_REPERTOARU.PREDSTAVA_U_PROSTORIJI_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('PREDSTAVA_NA_REPERTOARU')
            and   type = 'U')
   drop table PREDSTAVA_NA_REPERTOARU
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('PREVODILAC')
            and   name  = 'PREVODILAC_FK'
            and   indid > 0
            and   indid < 255)
   drop index PREVODILAC.PREVODILAC_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('PREVODILAC')
            and   name  = 'PREVODILAC2_FK'
            and   indid > 0
            and   indid < 255)
   drop index PREVODILAC.PREVODILAC2_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('PREVODILAC')
            and   type = 'U')
   drop table PREVODILAC
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('PROSTORIJA')
            and   name  = 'PROSTORIJA_POZORISTA_FK'
            and   indid > 0
            and   indid < 255)
   drop index PROSTORIJA.PROSTORIJA_POZORISTA_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('PROSTORIJA')
            and   type = 'U')
   drop table PROSTORIJA
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('P_D_PREDST')
            and   name  = 'P_D_PREDST_FK'
            and   indid > 0
            and   indid < 255)
   drop index P_D_PREDST.P_D_PREDST_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('P_D_PREDST')
            and   name  = 'P_D_PREDST2_FK'
            and   indid > 0
            and   indid < 255)
   drop index P_D_PREDST.P_D_PREDST2_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('P_D_PREDST')
            and   type = 'U')
   drop table P_D_PREDST
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('P_D_ULOGA')
            and   name  = 'P_D_ULOGA_FK'
            and   indid > 0
            and   indid < 255)
   drop index P_D_ULOGA.P_D_ULOGA_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('P_D_ULOGA')
            and   name  = 'P_D_ULOGA2_FK'
            and   indid > 0
            and   indid < 255)
   drop index P_D_ULOGA.P_D_ULOGA2_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('P_D_ULOGA')
            and   type = 'U')
   drop table P_D_ULOGA
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('UCESTVUJE_U_PREDSTAVI')
            and   name  = 'UCESTVUJE_U_PREDSTAVI_FK'
            and   indid > 0
            and   indid < 255)
   drop index UCESTVUJE_U_PREDSTAVI.UCESTVUJE_U_PREDSTAVI_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('UCESTVUJE_U_PREDSTAVI')
            and   name  = 'UCESTVUJE_U_PREDSTAVI2_FK'
            and   indid > 0
            and   indid < 255)
   drop index UCESTVUJE_U_PREDSTAVI.UCESTVUJE_U_PREDSTAVI2_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('UCESTVUJE_U_PREDSTAVI')
            and   type = 'U')
   drop table UCESTVUJE_U_PREDSTAVI
go

if exists (select 1
            from  sysobjects
           where  id = object_id('ULOGA')
            and   type = 'U')
   drop table ULOGA
go

if exists (select 1
            from  sysobjects
           where  id = object_id('ZANR')
            and   type = 'U')
   drop table ZANR
go

if exists (select 1
            from  sysobjects
           where  id = object_id('ZEMLJA')
            and   type = 'U')
   drop table ZEMLJA
go

/*==============================================================*/
/* Table: AUTOR                                                 */
/*==============================================================*/
create table AUTOR (
   SIF_POZ_DELA         int                  not null,
   SIF_LICA             int                  not null,
   constraint PK_AUTOR primary key nonclustered (SIF_POZ_DELA, SIF_LICA)
)
go

/*==============================================================*/
/* Index: AUTOR2_FK                                             */
/*==============================================================*/
create index AUTOR2_FK on AUTOR (
SIF_LICA ASC
)
go

/*==============================================================*/
/* Index: AUTOR_FK                                              */
/*==============================================================*/
create index AUTOR_FK on AUTOR (
SIF_POZ_DELA ASC
)
go

/*==============================================================*/
/* Table: LICE                                                  */
/*==============================================================*/
create table LICE (
   SIF_LICA             numeric              identity,
   SIF_MESTA            int                  not null,
   L_PREZIME            varchar(20)          not null,
   L_IME                varchar(20)          not null,
   POL                  char(1)              null
      constraint CKC_POL_LICE check (POL is null or (POL in ('<M>','<Z>'))),
   L_BIOGRAFIJA         varchar(5000)        null,
   L_IZ_VOJVODINE       bit                  not null,
   L_AMATER             bit                  not null,
   L_AKTIVNO            bit                  not null,
   constraint PK_LICE primary key nonclustered (SIF_LICA)
)
go

/*==============================================================*/
/* Index: BORAVI_FK                                             */
/*==============================================================*/
create index BORAVI_FK on LICE (
SIF_MESTA ASC
)
go

/*==============================================================*/
/* Table: LICE_U_ULOZI_PREDST_PROJ                              */
/*==============================================================*/
create table LICE_U_ULOZI_PREDST_PROJ (
   SIF_LICA             int                  not null,
   SIF_ULOGE            int                  not null,
   SIF_POZ_DELA         int                  not null,
   constraint PK_LICE_U_ULOZI_PREDST_PROJ primary key nonclustered (SIF_LICA, SIF_ULOGE, SIF_POZ_DELA)
)
go

/*==============================================================*/
/* Index: LICE_ULOGA_P_P_FK                                     */
/*==============================================================*/
create index LICE_ULOGA_P_P_FK on LICE_U_ULOZI_PREDST_PROJ (
SIF_LICA ASC
)
go

/*==============================================================*/
/* Index: LICE_U_ULOZI_P_D_FK                                   */
/*==============================================================*/
create index LICE_U_ULOZI_P_D_FK on LICE_U_ULOZI_PREDST_PROJ (
SIF_ULOGE ASC,
SIF_POZ_DELA ASC
)
go

/*==============================================================*/
/* Table: MESTO                                                 */
/*==============================================================*/
create table MESTO (
   SIF_MESTA            numeric              identity,
   SIF_ZEMLJE           int                  not null,
   NAZIV_MESTA          varchar(30)          not null,
   POST_BROJ            numeric(5)           not null,
   constraint PK_MESTO primary key nonclustered (SIF_MESTA)
)
go

/*==============================================================*/
/* Index: PRIPADA_FK                                            */
/*==============================================================*/
create index PRIPADA_FK on MESTO (
SIF_ZEMLJE ASC
)
go

/*==============================================================*/
/* Table: POZORISNO_DELO                                        */
/*==============================================================*/
create table POZORISNO_DELO (
   SIF_POZ_DELA         numeric              identity,
   SIF_ZANRA            int                  not null,
   NASLOV_POZ_DELA      varchar(50)          not null,
   POZ_DELO_BR_CINOVA   numeric(1)           not null,
   constraint PK_POZORISNO_DELO primary key nonclustered (SIF_POZ_DELA)
)
go

/*==============================================================*/
/* Index: ZANR_P_D_FK                                           */
/*==============================================================*/
create index ZANR_P_D_FK on POZORISNO_DELO (
SIF_ZANRA ASC
)
go

/*==============================================================*/
/* Table: POZORISTE                                             */
/*==============================================================*/
create table POZORISTE (
   SIF_POZORISTA        numeric              identity,
   SIF_MESTA            int                  not null,
   NAZIV_POZORISTA      varchar(100)         not null,
   P_POSTANSKI_BROJ     numeric(5)           not null,
   P_MESTO              varchar(30)          not null,
   P_ULICA_BROJ         varchar(30)          null,
   P_TELEFON            varchar(20)          null,
   P_WWW_ADRESA         varchar(100)         null,
   P_EMAIL              varchar(50)          null,
   P_IZ_VOJVODINE       bit                  not null,
   P_AMATERSKO          bit                  not null,
   constraint PK_POZORISTE primary key nonclustered (SIF_POZORISTA)
)
go

/*==============================================================*/
/* Index: RADI_FK                                               */
/*==============================================================*/
create index RADI_FK on POZORISTE (
SIF_MESTA ASC
)
go

/*==============================================================*/
/* Table: POZ_PREDST                                            */
/*==============================================================*/
create table POZ_PREDST (
   SIF_POZORISTA        int                  not null,
   SIF_PREDSTAVE        int                  not null,
   constraint PK_POZ_PREDST primary key nonclustered (SIF_POZORISTA, SIF_PREDSTAVE)
)
go

/*==============================================================*/
/* Index: POZ_PREDST2_FK                                        */
/*==============================================================*/
create index POZ_PREDST2_FK on POZ_PREDST (
SIF_PREDSTAVE ASC
)
go

/*==============================================================*/
/* Index: POZ_PREDST_FK                                         */
/*==============================================================*/
create index POZ_PREDST_FK on POZ_PREDST (
SIF_POZORISTA ASC
)
go

/*==============================================================*/
/* Table: PREDSTAVA                                             */
/*==============================================================*/
create table PREDSTAVA (
   SIF_PREDSTAVE        numeric              identity,
   NASLOV_PREDSTAVE     varchar(50)          not null,
   PREDST_BR_CINOVA     numeric(1)           not null,
   PREDST_SADRZAJ       varchar(5000)        null,
   PREDST_DAT_I_VREME_PREMIJERE datetime             not null,
   PREDST_DUZINA_U_MIN  numeric(3)           not null,
   NA_REPERTOARU        bit                  not null,
   constraint PK_PREDSTAVA primary key nonclustered (SIF_PREDSTAVE)
)
go

/*==============================================================*/
/* Table: PREDSTAVA_NA_REPERTOARU                               */
/*==============================================================*/
create table PREDSTAVA_NA_REPERTOARU (
   SIF_PREDSTAVE        int                  not null,
   SIF_POZORISTA        int                  not null,
   SIF_PROSTORIJE       int                  not null,
   POCETAK_PREDSTAVE    datetime             not null,
   constraint PK_PREDSTAVA_NA_REPERTOARU primary key nonclustered (SIF_PREDSTAVE, SIF_POZORISTA, SIF_PROSTORIJE, POCETAK_PREDSTAVE)
)
go

/*==============================================================*/
/* Index: PREDSTAVA_U_PROSTORIJI_FK                             */
/*==============================================================*/
create index PREDSTAVA_U_PROSTORIJI_FK on PREDSTAVA_NA_REPERTOARU (
SIF_POZORISTA ASC,
SIF_PROSTORIJE ASC
)
go

/*==============================================================*/
/* Index: PREDSTAVA_NA_REPERTOARU_FK                            */
/*==============================================================*/
create index PREDSTAVA_NA_REPERTOARU_FK on PREDSTAVA_NA_REPERTOARU (
SIF_PREDSTAVE ASC
)
go

/*==============================================================*/
/* Table: PREVODILAC                                            */
/*==============================================================*/
create table PREVODILAC (
   SIF_POZ_DELA         int                  not null,
   SIF_LICA             int                  not null,
   constraint PK_PREVODILAC primary key nonclustered (SIF_POZ_DELA, SIF_LICA)
)
go

/*==============================================================*/
/* Index: PREVODILAC2_FK                                        */
/*==============================================================*/
create index PREVODILAC2_FK on PREVODILAC (
SIF_LICA ASC
)
go

/*==============================================================*/
/* Index: PREVODILAC_FK                                         */
/*==============================================================*/
create index PREVODILAC_FK on PREVODILAC (
SIF_POZ_DELA ASC
)
go

/*==============================================================*/
/* Table: PROSTORIJA                                            */
/*==============================================================*/
create table PROSTORIJA (
   SIF_POZORISTA        int                  not null,
   SIF_PROSTORIJE       numeric              identity,
   NAZIV_PROSTORIJE     varchar(50)          not null,
   PR_BROJ_SEDISTA      numeric(3)           not null,
   constraint PK_PROSTORIJA primary key nonclustered (SIF_POZORISTA, SIF_PROSTORIJE)
)
go

/*==============================================================*/
/* Index: PROSTORIJA_POZORISTA_FK                               */
/*==============================================================*/
create index PROSTORIJA_POZORISTA_FK on PROSTORIJA (
SIF_POZORISTA ASC
)
go

/*==============================================================*/
/* Table: P_D_PREDST                                            */
/*==============================================================*/
create table P_D_PREDST (
   SIF_POZ_DELA         int                  not null,
   SIF_PREDSTAVE        int                  not null,
   constraint PK_P_D_PREDST primary key nonclustered (SIF_POZ_DELA, SIF_PREDSTAVE)
)
go

/*==============================================================*/
/* Index: P_D_PREDST2_FK                                        */
/*==============================================================*/
create index P_D_PREDST2_FK on P_D_PREDST (
SIF_PREDSTAVE ASC
)
go

/*==============================================================*/
/* Index: P_D_PREDST_FK                                         */
/*==============================================================*/
create index P_D_PREDST_FK on P_D_PREDST (
SIF_POZ_DELA ASC
)
go

/*==============================================================*/
/* Table: P_D_ULOGA                                             */
/*==============================================================*/
create table P_D_ULOGA (
   SIF_ULOGE            int                  not null,
   SIF_POZ_DELA         int                  not null,
   constraint PK_P_D_ULOGA primary key nonclustered (SIF_ULOGE, SIF_POZ_DELA)
)
go

/*==============================================================*/
/* Index: P_D_ULOGA2_FK                                         */
/*==============================================================*/
create index P_D_ULOGA2_FK on P_D_ULOGA (
SIF_POZ_DELA ASC
)
go

/*==============================================================*/
/* Index: P_D_ULOGA_FK                                          */
/*==============================================================*/
create index P_D_ULOGA_FK on P_D_ULOGA (
SIF_ULOGE ASC
)
go

/*==============================================================*/
/* Table: UCESTVUJE_U_PREDSTAVI                                 */
/*==============================================================*/
create table UCESTVUJE_U_PREDSTAVI (
   SIF_LICA             int                  not null,
   SIF_ULOGE            int                  not null,
   SIF_POZ_DELA         int                  not null,
   SIF_PREDSTAVE        int                  not null,
   SIF_POZORISTA        int                  not null,
   SIF_PROSTORIJE       int                  not null,
   POCETAK_PREDSTAVE    datetime             not null,
   constraint PK_UCESTVUJE_U_PREDSTAVI primary key nonclustered (SIF_LICA, SIF_ULOGE, SIF_POZ_DELA, SIF_PREDSTAVE, SIF_POZORISTA, SIF_PROSTORIJE, POCETAK_PREDSTAVE)
)
go

/*==============================================================*/
/* Index: UCESTVUJE_U_PREDSTAVI2_FK                             */
/*==============================================================*/
create index UCESTVUJE_U_PREDSTAVI2_FK on UCESTVUJE_U_PREDSTAVI (
SIF_PREDSTAVE ASC,
SIF_POZORISTA ASC,
SIF_PROSTORIJE ASC,
POCETAK_PREDSTAVE ASC
)
go

/*==============================================================*/
/* Index: UCESTVUJE_U_PREDSTAVI_FK                              */
/*==============================================================*/
create index UCESTVUJE_U_PREDSTAVI_FK on UCESTVUJE_U_PREDSTAVI (
SIF_LICA ASC,
SIF_ULOGE ASC,
SIF_POZ_DELA ASC
)
go

/*==============================================================*/
/* Table: ULOGA                                                 */
/*==============================================================*/
create table ULOGA (
   SIF_ULOGE            numeric              identity,
   ULOGA                varchar(30)          null,
   constraint PK_ULOGA primary key nonclustered (SIF_ULOGE)
)
go

/*==============================================================*/
/* Table: ZANR                                                  */
/*==============================================================*/
create table ZANR (
   SIF_ZANRA            numeric              identity,
   ZANR                 varchar(50)          not null,
   constraint PK_ZANR primary key nonclustered (SIF_ZANRA)
)
go

/*==============================================================*/
/* Table: ZEMLJA                                                */
/*==============================================================*/
create table ZEMLJA (
   SIF_ZEMLJE           numeric              identity,
   DRZAVA               varchar(30)          not null,
   OZNAKA_DRZAVE        char(5)              null,
   constraint PK_ZEMLJA primary key nonclustered (SIF_ZEMLJE),
   constraint AK_DRZAVA_ZEMLJA unique (DRZAVA)
)
go

alter table AUTOR
   add constraint FK_AUTOR_AUTOR_POZORISN foreign key (SIF_POZ_DELA)
      references POZORISNO_DELO (SIF_POZ_DELA)
go

alter table AUTOR
   add constraint FK_AUTOR_AUTOR2_LICE foreign key (SIF_LICA)
      references LICE (SIF_LICA)
go

alter table LICE
   add constraint FK_LICE_BORAVI_MESTO foreign key (SIF_MESTA)
      references MESTO (SIF_MESTA)
go

alter table LICE_U_ULOZI_PREDST_PROJ
   add constraint FK_LICE_U_U_LICE_ULOG_LICE foreign key (SIF_LICA)
      references LICE (SIF_LICA)
go

alter table LICE_U_ULOZI_PREDST_PROJ
   add constraint FK_LICE_U_U_LICE_U_UL_P_D_ULOG foreign key (SIF_ULOGE, SIF_POZ_DELA)
      references P_D_ULOGA (SIF_ULOGE, SIF_POZ_DELA)
go

alter table MESTO
   add constraint FK_MESTO_PRIPADA_ZEMLJA foreign key (SIF_ZEMLJE)
      references ZEMLJA (SIF_ZEMLJE)
go

alter table POZORISNO_DELO
   add constraint FK_POZORISN_ZANR_P_D_ZANR foreign key (SIF_ZANRA)
      references ZANR (SIF_ZANRA)
go

alter table POZORISTE
   add constraint FK_POZORIST_RADI_MESTO foreign key (SIF_MESTA)
      references MESTO (SIF_MESTA)
go

alter table POZ_PREDST
   add constraint FK_POZ_PRED_POZ_PREDS_POZORIST foreign key (SIF_POZORISTA)
      references POZORISTE (SIF_POZORISTA)
go

alter table POZ_PREDST
   add constraint FK_POZ_PRED_POZ_PREDS_PREDSTAV foreign key (SIF_PREDSTAVE)
      references PREDSTAVA (SIF_PREDSTAVE)
go

alter table PREDSTAVA_NA_REPERTOARU
   add constraint FK_PREDSTAV_PREDSTAVA_PREDSTAV foreign key (SIF_PREDSTAVE)
      references PREDSTAVA (SIF_PREDSTAVE)
go

alter table PREDSTAVA_NA_REPERTOARU
   add constraint FK_PREDSTAV_PREDSTAVA_PROSTORI foreign key (SIF_POZORISTA, SIF_PROSTORIJE)
      references PROSTORIJA (SIF_POZORISTA, SIF_PROSTORIJE)
go

alter table PREVODILAC
   add constraint FK_PREVODIL_PREVODILA_POZORISN foreign key (SIF_POZ_DELA)
      references POZORISNO_DELO (SIF_POZ_DELA)
go

alter table PREVODILAC
   add constraint FK_PREVODIL_PREVODILA_LICE foreign key (SIF_LICA)
      references LICE (SIF_LICA)
go

alter table PROSTORIJA
   add constraint FK_PROSTORI_PROSTORIJ_POZORIST foreign key (SIF_POZORISTA)
      references POZORISTE (SIF_POZORISTA)
go

alter table P_D_PREDST
   add constraint FK_P_D_PRED_P_D_PREDS_POZORISN foreign key (SIF_POZ_DELA)
      references POZORISNO_DELO (SIF_POZ_DELA)
go

alter table P_D_PREDST
   add constraint FK_P_D_PRED_P_D_PREDS_PREDSTAV foreign key (SIF_PREDSTAVE)
      references PREDSTAVA (SIF_PREDSTAVE)
go

alter table P_D_ULOGA
   add constraint FK_P_D_ULOG_P_D_ULOGA_ULOGA foreign key (SIF_ULOGE)
      references ULOGA (SIF_ULOGE)
go

alter table P_D_ULOGA
   add constraint FK_P_D_ULOG_P_D_ULOGA_POZORISN foreign key (SIF_POZ_DELA)
      references POZORISNO_DELO (SIF_POZ_DELA)
go

alter table UCESTVUJE_U_PREDSTAVI
   add constraint FK_UCESTVUJ_UCESTVUJE_LICE_U_U foreign key (SIF_LICA, SIF_ULOGE, SIF_POZ_DELA)
      references LICE_U_ULOZI_PREDST_PROJ (SIF_LICA, SIF_ULOGE, SIF_POZ_DELA)
go

alter table UCESTVUJE_U_PREDSTAVI
   add constraint FK_UCESTVUJ_UCESTVUJE_PREDSTAV foreign key (SIF_PREDSTAVE, SIF_POZORISTA, SIF_PROSTORIJE, POCETAK_PREDSTAVE)
      references PREDSTAVA_NA_REPERTOARU (SIF_PREDSTAVE, SIF_POZORISTA, SIF_PROSTORIJE, POCETAK_PREDSTAVE)
go

