Delimiter //
Drop Procedure if exists LOADER_CREATE_TABLE_ACCOUNTS//
Create Procedure LOADER_CREATE_TABLE_ACCOUNTS ()
Begin

    Drop Table If Exists LOADER_ACCOUNTS;

    Create Table LOADER_ACCOUNTS (

        -- champ auto increment, initialisé avant chanque import
        ID_LOADER_ACCOUNTS Int Unsigned Not Null Auto_increment,

        -- champs pour le traitements de l'import
        LOADER_STATUS_ID_LOADER_STATUS Int Unsigned Not Null,

        -- General, references
        ACCOUNTS_REF Varchar(40) Null,
        ID_ACCOUNTS Int Unsigned Null,
        ID_ACCOUNTS_NEW Int Unsigned Null,

        -- Type
        ACCOUNTS_TYPE Varchar(20) Null,
        DF_ACCOUNTS_TYPES_ID_DF_ACCOUNTS_TYPES Int(10) Unsigned Null,

        -- Category
        ACCOUNTS_CATEG Varchar(20) Null,
        DF_ACC_CATEG_ID_DF_ACC_CATEG Int(10) Unsigned Null,

        -- Dates
        ACCOUNTS_CREATED Date Null, -- not null
        ACCOUNTS_LAST_EVENT_UPDATE Date Null, -- not null

        -- Currency
        DF_CURRENCIES_CODE VarChar(3) Null,
        DF_CURRENCIES_ID_DF_CURRENCIES int(10) Unsigned Null,

        -- Intérêts
        DF_RATE_GRID_CODE Varchar(10) Null,
        DF_RATE_GRID_ID_DF_RATE_GRID int(10) Unsigned Null,

        -- Types de créance
        DF_DEBTS_TYPES_CODE Varchar(45) Null,
        DF_DEBTS_TYPES_ID_DF_DEBTS_TYPES int(10) Unsigned Null,

        DF_PENALTIES_RULES_CODE_FR4416 varchar(45), -- FR.441-6
        ID_DF_PENALTIES_RULES_CODE_FR4416 int(10) Unsigned Null, 

        DF_PENALTIES_RULES_CODE_FRLTPNCSE varchar(45), -- FR.LATE_PENAL_CAUSE
        ID_DF_PENALTIES_RULES_CODE_FRLTPNCSE int(10) Unsigned Null, 

        -- Currency
        ENTITIES_AGENCIES_CODE Varchar(45) Null,
        ENTITIES_AGENCIES_ID_ENTITIES_AGENCIES int(10) Unsigned Null,

        -- scores
        FI_ANA_CASH_ASSESSMENT SmallInt(5) Null,
        FI_ANA_CASH_ASSSSMNTLASTUPDAT Date Null,

        FI_ANA_INTERNAL_SCORE_RATING SmallInt(5) Null,
        FI_ANA_INTRSCORRATLASTUPDAT Date Null,

        FI_ANA_EXTERNAL_SCORE_RATING SmallInt(5) Null,
        FI_ANA_EXTSCORRATLASTUPDAT Date Null,

        ACCOUNTS_STATUS_VAL_DATE Date Null, 
        ACCOUNTS_STATUS_COMMENT Varchar(100) Null,
        DF_ACCOUNTS_STATUS_CODE Varchar(32) Null,
        DF_ACCOUNTS_STATUS_ID_DF_ACCOUNTS_STATUS Int Unsigned Null, 

        -- Fixed data
        DF_PRIORITY_ID_DF_PRIORITY Int(10) Unsigned Null,
        DF_SAND_STATE_ID_DF_SAND_STATE Int(10) Unsigned Null,
        DF_MNGT_LVL_ID_DF_MNGT_LVL Int(10) Unsigned Null,
        DF_SCAN_TYPE_ID_DF_SCAN_TYPE Int(10) Unsigned Null,

        -- contraintes et indexes
        Primary Key (ID_LOADER_ACCOUNTS)
        , Index (LOADER_STATUS_ID_LOADER_STATUS)
        , Index (ID_ACCOUNTS)
        , Index (ACCOUNTS_REF)

    ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

End //
Delimiter ;
call LOADER_CREATE_TABLE_ACCOUNTS();