# ---------------------------------------------------------------------- #
# Add table "TIPO_NEWS"                                                  #
# ---------------------------------------------------------------------- #

CREATE TABLE `TIPO_NEWS` (
    `id_tipoNews` INTEGER NOT NULL AUTO_INCREMENT,
    `descrizione` VARCHAR(60),
    `lastUpdId_user` INTEGER,
    `lastUpdTmst` TIMESTAMP,
    CONSTRAINT `PK_TIPO_NEWS` PRIMARY KEY (`id_tipoNews`)
);

# ---------------------------------------------------------------------- #
# Add table "NEWS"                                                       #
# ---------------------------------------------------------------------- #

CREATE TABLE `NEWS` (
    `id_news` INTEGER NOT NULL AUTO_INCREMENT,
    `dataNews` DATE,
  
    `flgVisibile` INTEGER,
    `dataFineVld` DATE,
   
    `lastUpdTmst` TIMESTAMP,
    `lastUpdId_user` INTEGER,
    `imgTmst` CHAR(16),
    `id_tipoNews` INTEGER,
    CONSTRAINT `PK_NEWS` PRIMARY KEY (`id_news`)
);

# ---------------------------------------------------------------------- #
# Add table "ALLEGATO_NEWS"                                              #
# ---------------------------------------------------------------------- #

CREATE TABLE `ALLEGATO_NEWS` (
    `id_allegatoNews` INTEGER NOT NULL AUTO_INCREMENT,
    `nomeFile` VARCHAR(60),
    `id_news` INTEGER(11),
    `lastUpdId_user` INTEGER,
    `lastUpdTmst` TIMESTAMP,
    `descrizioneAllegato` VARCHAR(254),
    CONSTRAINT `PK_ALLEGATO_NEWS` PRIMARY KEY (`id_allegatoNews`)
);

CREATE INDEX `IDX_ALLEGATO_NEWS_1` ON `ALLEGATO_NEWS` (`id_news`);

ALTER TABLE `NEWS` ADD CONSTRAINT `TIPO_NEWS_NEWS` 
    FOREIGN KEY (`id_tipoNews`) REFERENCES `TIPO_NEWS` (`id_tipoNews`);

ALTER TABLE `ALLEGATO_NEWS` ADD CONSTRAINT `NEWS_ALLEGATO_NEWS` 
    FOREIGN KEY (`id_news`) REFERENCES `NEWS` (`id_news`);