/**Begin D:\PDM\pdm_upgrade\pdm1\ER_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_MEALAPPLICATION_BILL')
CREATE TABLE T_ER_MEALAPPLICATION_BILL (
                                           FID BIGINT DEFAULT 0 NOT NULL,
                                           FTEL VARCHAR(50) DEFAULT ' ' NOT NULL,
                                           FCOMPANYID BIGINT DEFAULT 0 NOT NULL,
                                           FBILLNO VARCHAR(30) DEFAULT ' ' NOT NULL,
                                           FCHANGEDATE DATETIME,
                                           FDESCRIPTION VARCHAR(600) DEFAULT ' ' NOT NULL,
                                           FCOSTDEPT BIGINT DEFAULT 0 NOT NULL,
                                           FCOSTCOMPANYID BIGINT DEFAULT 0 NOT NULL,
                                           FTRIPEXPENSEITEM BIGINT DEFAULT 0 NOT NULL,
                                           FDINNERSCENE VARCHAR(50) DEFAULT ' ' NOT NULL,
                                           FSTARTDATE DATETIME,
                                           FENDDATE DATETIME,
                                           FCITYFIELD BIGINT DEFAULT 0 NOT NULL,
                                           FINTERNALHIGHESTLEVEL BIGINT DEFAULT 0 NOT NULL,
                                           FDINNERSTANDARD VARCHAR(50) DEFAULT ' ' NOT NULL,
                                           FDINNERUSERNUM VARCHAR(50) DEFAULT ' ' NOT NULL,
                                           FDINNERAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
                                           FBILLSTATUS VARCHAR(50) DEFAULT ' ' NOT NULL,
                                           FNEXTAUDITOR VARCHAR(50) DEFAULT ' ' NOT NULL,
                                           FCREATETIME DATETIME,
                                           FAUDITDATE DATETIME,
                                           FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
                                           FMODIFYTIME DATETIME,
                                           FCREATORID BIGINT DEFAULT 0 NOT NULL,
                                           FAUDITORID BIGINT DEFAULT 0 NOT NULL,
                                           FAPPLIERID BIGINT DEFAULT 0 NOT NULL,
                                           FORGID BIGINT DEFAULT 0 NOT NULL,
                                           FAPPLIERPOSITION VARCHAR(50) DEFAULT ' ' NOT NULL,
                                           FCURRENCYID BIGINT DEFAULT 0 NOT NULL,
                                           FBIZDATE DATETIME
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_INTERNALUSER')
CREATE TABLE T_ER_INTERNALUSER (
                                   FPKID BIGINT DEFAULT 0 NOT NULL,
                                   FID BIGINT DEFAULT 0 NOT NULL,
                                   FBASEDATAID BIGINT DEFAULT 0 NOT NULL
);

EXEC P_ALTERPK 'PK_T_ER_MEALAPPLICATION_BILL', 'T_ER_MEALAPPLICATION_BILL', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_MEALAPPLICATIONBILL_FK') CREATE INDEX IDX_ER_MEALAPPLICATIONBILL_FK ON T_ER_MEALAPPLICATION_BILL ( FBILLNO );
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_MBILL_FBIZDATE_FBILLNO') CREATE INDEX IDX_ER_MBILL_FBIZDATE_FBILLNO ON T_ER_MEALAPPLICATION_BILL ( FBILLNO,FBIZDATE );
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_MBILL_FCOMPANYID') CREATE INDEX IDX_ER_MBILL_FCOMPANYID ON T_ER_MEALAPPLICATION_BILL ( FCOMPANYID );


EXEC P_ALTERPK 'PK_T_ER_INTERNALUSER', 'T_ER_INTERNALUSER', 'FPKID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_INTERNALUSER_FK') CREATE INDEX IDX_ER_INTERNALUSER_FK ON T_ER_INTERNALUSER ( FID );


/**End D:\PDM\pdm_upgrade\pdm1\ER_table.sql **/
