Delimiter //
/**
 * Author:  Benoit DD <b.danquechindorval@amo-soft.com>
 * Created: 7 déc. 2015
 */
Drop Procedure if exists LOADER_CREATE_TABLE_CREDITLIMIT//
Create Procedure LOADER_CREATE_TABLE_CREDITLIMIT ()
Begin
    Drop Table If Exists LOADER_CREDITLIMIT;
    
    Create Table LOADER_CREDITLIMIT (
        ID_LOADER_CREDITLIMIT 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

        , CONTACTS_BUSINESS_SIRET varchar(15) null

        , CREDIT_LIMIT_DATE Date Null
        , CREDIT_LIMIT_AMOUNT Decimal(19,4) Null
        , CREDIT_LIMIT_VAL_DATE Date Null
        , CREDIT_LIMIT_COMMENT Varchar(200) Null

        , LOADER_CREDITLIMIT_MAIN_CONTACT_ONLY SmallInt Not Null default 0
--         , ID_CREDIT_LIMIT Int Unsigned Null
--         , ID_CREDIT_LIMIT_NEW Int Unsigned Null

        -- contraintes et indexes
        , Primary Key (ID_LOADER_CREDITLIMIT)
        , Index (LOADER_STATUS_ID_LOADER_STATUS)
--         , Index (ACCOUNTS_ID_ACCOUNTS)
        , Index (ACCOUNTS_REF)
--         , Index (CONTACTS_BUSINESS_SIRET)

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