
IF EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_SUPPLIEREXC' AND KSQL_COL_NAME IN ('FORGID')) 
 DROP TABLE T_BD_SUPPLIEREXC;
 
IF EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_BD_CUSTOMEREXC' AND KSQL_COL_NAME IN ('FORGID')) 
 DROP TABLE T_BD_CUSTOMEREXC;

 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BD_SUPPLIEREXC') 
 CREATE TABLE T_BD_SUPPLIEREXC (
FDATAID BIGINT NOT NULL,
FCREATEORGID BIGINT,
FUSEORGID BIGINT NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BD_CUSTOMEREXC') 
 CREATE TABLE T_BD_CUSTOMEREXC (
FDATAID BIGINT NOT NULL,
FCREATEORGID BIGINT,
FUSEORGID BIGINT NOT NULL
);

 EXEC P_ALTERPK 'PK_T_BD_SUPPLIEREXC', 'T_BD_SUPPLIEREXC', 'FDATAID,FUSEORGID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_BD_SUPPLIEREXC_UO') CREATE INDEX IDX_BD_SUPPLIEREXC_UO ON T_BD_SUPPLIEREXC ( FUSEORGID );

 EXEC P_ALTERPK 'PK_T_BD_CUSTOMEREXC', 'T_BD_CUSTOMEREXC', 'FDATAID,FUSEORGID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_BD_CUSTOMEREXC_UO') CREATE INDEX IDX_BD_CUSTOMEREXC_UO ON T_BD_CUSTOMEREXC ( FUSEORGID );
 
 