CREATE TABLE `assg_rtng_f` (
  `RTNG_ID` int(11) NOT NULL,
  `ASSG_RTNG_CONTATORE` int(11) DEFAULT NULL,
  `NUMERO_DT_PERIODO` int(11) NOT NULL,
  PRIMARY KEY (`RTNG_ID`,`NUMERO_DT_PERIODO`),
  KEY `ASSG_CALE_FK` (`NUMERO_DT_PERIODO`),
  CONSTRAINT `ASSG_CALE_FK` FOREIGN KEY (`NUMERO_DT_PERIODO`) REFERENCES `calendario_dt_d` (`NUMERO_DT_PERIODO`),
  CONSTRAINT `ASSG_RTNG_FK` FOREIGN KEY (`RTNG_ID`) REFERENCES `rtng_d` (`RTNG_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `calendario_dt_d` (
  `NUMERO_DT_PERIODO` int(11) NOT NULL,
  `NUMERO_MESE` int(11) DEFAULT NULL,
  `NM_MESE` varchar(20) DEFAULT NULL,
  `NUMERO_ANNO_MESE` int(11) DEFAULT NULL,
  `NUMERO_TRIMESTRE` int(11) DEFAULT NULL,
  `NUMERO_SETTIMANA` int(11) DEFAULT NULL,
  `NUMERO_ANNO` int(11) DEFAULT NULL,
  `FLG_COMPAGNIA_VACANZA` char(1) DEFAULT NULL,
  `NUMERO_GIORNO_MESE` int(11) DEFAULT NULL,
  `NUMERO_GIORNO_ANNO` int(11) DEFAULT NULL,
  `NUMERO_GIORNO_SETTIMANA` varchar(50) DEFAULT NULL,
  `FLG_ULTIMO_GIORNO_MESE` char(1) DEFAULT NULL,
  `FLG_PUBBLICO_VACANZA` char(1) DEFAULT NULL,
  `FLG_BRS_VACANZA` char(1) DEFAULT NULL,
  `NUMERO_SETTIMANA_MESE` int(11) DEFAULT NULL,
  `NUMERO_SETTIMANA_ANNO` int(11) DEFAULT NULL,
  `FLG_GIORNO_FERIALE` char(1) DEFAULT NULL,
  PRIMARY KEY (`NUMERO_DT_PERIODO`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `cnctr_f` (
  `CNTRP_EMT_ID` int(11) NOT NULL,
  `PRTFGL_ID` int(11) NOT NULL,
  `INV` decimal(17,2) DEFAULT NULL,
  `PTRM_OGG` decimal(21,3) DEFAULT NULL,
  `PTRM_SOGG` decimal(21,3) DEFAULT NULL,
  `DT_ASSG` date DEFAULT NULL,
  `DT_SCDN` date DEFAULT NULL,
  `PIVA_SGR` varchar(11) DEFAULT NULL,
  `DT_INS` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `DT_AGG` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `STM_SRG` varchar(50) DEFAULT NULL,
  `CD_AMB` varchar(50) DEFAULT NULL,
  `NUMERO_DT_PERIODO` int(11) NOT NULL,
  `RTNG_ID` int(11) NOT NULL,
  `OICR_SOGG_ID` int(11) NOT NULL,
  `OICR_OGG_ID` int(11) NOT NULL,
  PRIMARY KEY (`CNTRP_EMT_ID`,`PRTFGL_ID`,`NUMERO_DT_PERIODO`,`RTNG_ID`,`OICR_SOGG_ID`,`OICR_OGG_ID`),
  KEY `CNCT_RTNG_FK` (`RTNG_ID`),
  KEY `CNCT_PRTF_FK` (`PRTFGL_ID`),
  KEY `CNCT_CALE_FK` (`NUMERO_DT_PERIODO`),
  KEY `CNCT_OICR_FK` (`OICR_SOGG_ID`),
  KEY `CNCT_OICR_FK1` (`OICR_OGG_ID`),
  CONSTRAINT `CNCT_CALE_FK` FOREIGN KEY (`NUMERO_DT_PERIODO`) REFERENCES `calendario_dt_d` (`NUMERO_DT_PERIODO`),
  CONSTRAINT `CNCT_CNTR_FK` FOREIGN KEY (`CNTRP_EMT_ID`) REFERENCES `cntrp_emt_d` (`CNTRP_EMT_ID`),
  CONSTRAINT `CNCT_OICR_FK` FOREIGN KEY (`OICR_SOGG_ID`) REFERENCES `oicr_d` (`OICR_ID`),
  CONSTRAINT `CNCT_OICR_FK1` FOREIGN KEY (`OICR_OGG_ID`) REFERENCES `oicr_d` (`OICR_ID`),
  CONSTRAINT `CNCT_PRTF_FK` FOREIGN KEY (`PRTFGL_ID`) REFERENCES `prtfgl_d` (`PRTFGL_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `cntrp_brs_d` (
  `CNTRP_BRS_ID` int(11) NOT NULL,
  `CNTRP_BRS_NM` varchar(100) DEFAULT NULL,
  `CNTRP_BRS_PIVA` varchar(11) DEFAULT NULL,
  `CNTRP_BRS_CD_FIS` varchar(16) DEFAULT NULL,
  `CNTRP_BRS_CD` varchar(50) DEFAULT NULL,
  `CNTRP_BRS_ABI` varchar(5) DEFAULT NULL,
  `CNTRP_BRS_IBAN` varchar(34) DEFAULT NULL,
  `CNTRP_BRS_TP_AGN` varchar(40) DEFAULT NULL,
  `CNTRP_BRS_INDR_DS` varchar(30) DEFAULT NULL,
  `CNTRP_BRS_CAP` varchar(5) DEFAULT NULL,
  `CNTRP_BRS_LCLT` varchar(24) DEFAULT NULL,
  `CNTRP_BRS_PRVNC` varchar(2) DEFAULT NULL,
  `CNTRP_BRS_NZ_CD` varchar(3) DEFAULT NULL,
  `CNTRP_BRS_NZ_DS` varchar(40) DEFAULT NULL,
  `CNTRP_BRS_EMT_CD` varchar(6) DEFAULT NULL,
  `PIVA_SGR` varchar(11) DEFAULT NULL,
  `DT_INS` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `DT_AGG` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `STM_SRG` varchar(50) DEFAULT NULL,
  `CD_AMB` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`CNTRP_BRS_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `cntrp_emt_d` (
  `CNTRP_EMT_ID` int(11) NOT NULL,
  `CNTRP_EMT_NM` varchar(100) DEFAULT NULL,
  `CNTRP_EMT_CD` varchar(50) DEFAULT NULL,
  `CNTRP_EMT_INDR_DS` varchar(30) DEFAULT NULL,
  `CNTRP_EMT_CAP` varchar(5) DEFAULT NULL,
  `CNTRP_EMT_LCLT` varchar(24) DEFAULT NULL,
  `CNTRP_EMT_PRVNC` varchar(2) DEFAULT NULL,
  `CNTRP_EMT_NZ_CD` varchar(3) DEFAULT NULL,
  `CNTRP_EMT_NZ_DS` varchar(40) DEFAULT NULL,
  `CNTRP_STT_ATT_ECNM_CD` varchar(3) DEFAULT NULL,
  `CNTRP_STT_ATT_ECNM_DS` varchar(40) DEFAULT NULL,
  `CNTRP_EMT_CTG_EMT_CD` varchar(3) DEFAULT NULL,
  `CNTRP_EMT_CTG_EMT_DS` varchar(40) DEFAULT NULL,
  `CNTRP_EMT_GRP_NM` varchar(100) DEFAULT NULL,
  `PIVA_SGR` varchar(11) DEFAULT NULL,
  `DT_INS` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `DT_AGG` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `STM_SRG` varchar(50) DEFAULT NULL,
  `CD_AMB` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`CNTRP_EMT_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `oicr_d` (
  `OICR_ID` int(11) NOT NULL,
  `OICR_CD_FND` varchar(2) DEFAULT NULL,
  `OICR_ID_BB_UNQ` varchar(50) DEFAULT NULL,
  `OICR_CD_TTL` varchar(50) DEFAULT NULL,
  `OICR_ISIN` varchar(12) DEFAULT NULL,
  `OICR_TCKR` varchar(50) DEFAULT NULL,
  `OICR_DS` varchar(40) DEFAULT NULL,
  `OICR_FULL_NAME` varchar(100) DEFAULT NULL,
  `OICR_CNTRP_EMT_NM` varchar(100) DEFAULT NULL,
  `OICR_STT_ATT_ECNM_CD` varchar(3) DEFAULT NULL,
  `OICR_STT_ATT_ECNM_DS` varchar(40) DEFAULT NULL,
  `OICR_CD_BRS_CD` varchar(14) DEFAULT NULL,
  `OICR_CD_BRS_NM` varchar(30) DEFAULT NULL,
  `OICR_CTG_VAL_MOB_CD` varchar(7) DEFAULT NULL,
  `OICR_CTG_VAL_MOB_DS_` varchar(40) DEFAULT NULL,
  `OICR_DVS_CD` varchar(14) DEFAULT NULL,
  `OICR_DVS_DS` varchar(30) DEFAULT NULL,
  `OICR_MSTR_CNT_CD` varchar(14) DEFAULT NULL,
  `OICR_MSTR_CNT_DS` varchar(30) DEFAULT NULL,
  `OICR_STR_FNZ_TP` varchar(50) DEFAULT NULL,
  `OICR_IND_OICR` varchar(6) DEFAULT NULL,
  `OICR_TP_FND` varchar(50) DEFAULT NULL,
  `OICR_DT_FN_VLDT` date DEFAULT NULL,
  `OICR_FLG_CNTR` varchar(3) DEFAULT NULL,
  `OICR_CLSSF_LVL_1` varchar(50) DEFAULT NULL,
  `OICR_CLSSF_LVL_2` varchar(50) DEFAULT NULL,
  `OICR_CLSSF_LVL_3` varchar(50) DEFAULT NULL,
  `OICR_CLSSF_LVL_4` varchar(50) DEFAULT NULL,
  `OICR_CLSSF_LVL_5` varchar(50) DEFAULT NULL,
  `OICR_CLSSF_LVL_6` varchar(50) DEFAULT NULL,
  `OICR_CLSSF_LVL_7` varchar(50) DEFAULT NULL,
  `OICR_CLSSF_LVL_8` varchar(50) DEFAULT NULL,
  `OICR_CLSSF_LVL_9` varchar(50) DEFAULT NULL,
  `OICR_CLSSF_LVL_10` varchar(50) DEFAULT NULL,
  `OICR_CLSSF_LVL_11` varchar(50) DEFAULT NULL,
  `OICR_CLSSF_LVL_12` varchar(50) DEFAULT NULL,
  `OICR_CLSSF_LVL_13` varchar(50) DEFAULT NULL,
  `OICR_CLSSF_LVL_14` varchar(50) DEFAULT NULL,
  `OICR_CLSSF_LVL_15` varchar(50) DEFAULT NULL,
  `OICR_PRP_POL_GST` varchar(50) DEFAULT NULL,
  `OICR_PRP_PRTFGL_MNGR` varchar(50) DEFAULT NULL,
  `OICR_TRZ_FLG_UNV_INVB` varchar(3) DEFAULT NULL,
  `PIVA_SGR` varchar(11) DEFAULT NULL,
  `DT_INS` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `DT_AGG` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `STM_SRG` varchar(50) DEFAULT NULL,
  `CD_AMB` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`OICR_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `param` (
  `PIVA_SGR` varchar(11) NOT NULL,
  `SGR_NM` varchar(255) DEFAULT NULL,
  `LMT_DS_1` varchar(50) DEFAULT NULL,
  `PERC_1` decimal(5,2) DEFAULT NULL,
  `LMT_DS_2` varchar(50) DEFAULT NULL,
  `PERC_2` decimal(5,2) DEFAULT NULL,
  `LMT_DS_3` varchar(50) DEFAULT NULL,
  `PERC_3` decimal(5,2) DEFAULT NULL,
  `LOGO_INT` varchar(255) DEFAULT NULL,
  `LOGO_EST_1` varchar(255) DEFAULT NULL,
  `LOGO_EST_2` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`PIVA_SGR`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `prtfgl_d` (
  `PRTFGL_ID` int(11) NOT NULL,
  `PRTFGL_DT` date DEFAULT NULL,
  `PRTFGL_STR_FNZ_SOGG_TCKR` varchar(50) DEFAULT NULL,
  `PRTFGL_STR_FNZ_SOGG_DS` varchar(40) DEFAULT NULL,
  `PRTFGL_STR_FNZ_SOGG_FULL_NAME` varchar(100) DEFAULT NULL,
  `PRTFGL_STR_FNZ_OGG_TCKR` varchar(50) DEFAULT NULL,
  `PRTFGL_STR_FNZ_OGG_DS` varchar(40) DEFAULT NULL,
  `PRTFGL_STR_FNZ_OGG_FULL_NAME` varchar(100) DEFAULT NULL,
  `PIVA_SGR` varchar(11) DEFAULT NULL,
  `DT_INS` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `DT_AGG` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `STM_SRG` varchar(50) DEFAULT NULL,
  `CD_AMB` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`PRTFGL_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `rtng_d` (
  `RTNG_ID` int(11) NOT NULL,
  `RTNG_NM` varchar(30) DEFAULT NULL,
  `RTNG_TP_DS` varchar(30) DEFAULT NULL,
  `DT_INIZIO_RIGA` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `DT_FN_RIGA` datetime DEFAULT NULL,
  `IND_CORRENTE` char(1) DEFAULT NULL,
  `RTNG_LMT_ID` int(11) NOT NULL,
  `PIVA_SGR` varchar(11) DEFAULT NULL,
  `DT_INS` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `DT_AGG` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `STM_SRG` varchar(50) DEFAULT NULL,
  `CD_AMB` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`RTNG_ID`),
  KEY `RTNG_RTNG_FK` (`RTNG_LMT_ID`),
  CONSTRAINT `RTNG_RTNG_FK` FOREIGN KEY (`RTNG_LMT_ID`) REFERENCES `rtng_lmt` (`RTNG_LMT_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `rtng_lmt` (
  `RTNG_LMT_ID` int(11) NOT NULL,
  `RTNG_NM` varchar(30) DEFAULT NULL,
  `POL_GST` varchar(50) DEFAULT NULL,
  `RTNG_TP_DS` varchar(30) DEFAULT NULL,
  `PERC` decimal(5,2) DEFAULT NULL,
  `DT_INIZIO` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `DT_FN` datetime DEFAULT NULL,
  `IND_CORRENTE` char(1) DEFAULT NULL,
  `PIVA_SGR` varchar(11) DEFAULT NULL,
  `DT_INS` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `DT_AGG` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `STM_SRG` varchar(50) DEFAULT NULL,
  `CD_AMB` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`RTNG_LMT_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `security` (
  `SEC_TYPE` varchar(50) DEFAULT NULL,
  `USER_GROUP` varchar(255) DEFAULT NULL,
  `SEC_FILTER` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;