Delimiter //
/**
 * Author:  Benoit DD <b.danquechindorval@amo-soft.com>
 * Created: 7 déc. 2015
 */
Drop Procedure if exists LOADER_CREATE_TABLE_GUARANTEED//
Create Procedure LOADER_CREATE_TABLE_GUARANTEED ()
Begin
    Drop Table If Exists LOADER_GUARANTEED;
    
    Create Table LOADER_GUARANTEED (
        ID_LOADER_GUARANTEED Int Unsigned Not Null Auto_increment
        -- champs pour le traitements de l'import
        , LOADER_STATUS_ID_LOADER_STATUS Int Unsigned Not Null

        -- champ de références
        , ACCOUNTS_REF Varchar(40) Null -- reference du compte. fourni par le fichier
        , ACCOUNTS_ID_ACCOUNTS Int Unsigned Null -- id du compte issu normalisation

        , GUARANTEED_NAME Varchar(30)
        , GUARANTEED_CREAT_DATE Datetime Null
        , GUARANTEED_AMOUNT Decimal(19,4) Null
        , GUARANTEED_VAL_DATE Date Null
        , GUARANTEED_COMMENT Varchar(100) Null
        , ID_GUARANTEED Int Unsigned Null
        , ID_GUARANTEED_NEW Int Unsigned Null

        -- contraintes et indexes
        , Primary Key (ID_LOADER_GUARANTEED)
        , Index (LOADER_STATUS_ID_LOADER_STATUS)
        , Index (ACCOUNTS_ID_ACCOUNTS)
        , Index (ACCOUNTS_REF)
        , Index (GUARANTEED_AMOUNT)

    ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
End //
Delimiter ;
call LOADER_CREATE_TABLE_GUARANTEED();