


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_CONTRACTPROJECT')
CREATE TABLE T_ER_CONTRACTPROJECT (
                                      FID BIGINT DEFAULT 0 NOT NULL,
                                      FENTRYID BIGINT DEFAULT 0 NOT NULL,
                                      FSEQ INT DEFAULT 0 NOT NULL,
                                      FPROJECTNO VARCHAR(50) DEFAULT ' ' NOT NULL,
                                      FPROJECTAPPLIER BIGINT DEFAULT 0 NOT NULL,
                                      FPROJECTBIZDATE DATETIME,
                                      FPROJECTDESCRIPTION NVARCHAR(100) DEFAULT ' ' NOT NULL,
                                      FPROJECTWTYPE VARCHAR(50) DEFAULT ' ' NOT NULL,
                                      FPROJECTWUNIT BIGINT DEFAULT 0 NOT NULL,
                                      FPROJECTITEM BIGINT DEFAULT 0 NOT NULL,
                                      FPROJECTCURRENCY BIGINT DEFAULT 0 NOT NULL,
                                      FPROJECTCHANGERATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
                                      FPROJECTQUOTETYPE CHAR(1) DEFAULT ' ' NOT NULL,
                                      FORIPROJECTCANAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
                                      FPROJECTCANAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
                                      FORIPROJECTWRITEOFFAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
                                      FPROJECTWRITEOFFAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
                                      FPROJECTCOSTORG BIGINT DEFAULT 00 NOT NULL,
                                      FSOURCEBILLID BIGINT DEFAULT 0 NOT NULL,
                                      FSOURCEENTRYID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_CONTRACTPROJECT_LK')
CREATE TABLE T_ER_CONTRACTPROJECT_LK (
                                         FID BIGINT DEFAULT 0 NOT NULL,
                                         FPKID BIGINT DEFAULT 0 NOT NULL,
                                         FSEQ INT DEFAULT 0 NOT NULL,
                                         FSTABLEID BIGINT DEFAULT 0 NOT NULL,
                                         FSBILLID BIGINT DEFAULT 0 NOT NULL,
                                         FSID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_APPLYPROJECTBILL_S')
CREATE TABLE T_ER_APPLYPROJECTBILL_S (
                                         FID BIGINT DEFAULT 0 NOT NULL,
                                         FCONTRACTAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
                                         FCANCONTRACTAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_APPLYPROJECTENTRY_S')
CREATE TABLE T_ER_APPLYPROJECTENTRY_S (
                                          FID BIGINT DEFAULT 0 NOT NULL,
                                          FENTRYID BIGINT DEFAULT 0 NOT NULL,
                                          FORIEXPCONTRACTAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
                                          FEXPCONTRACTAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
                                          FORIEXPCANCONTRACTAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
                                          FEXPCANCONTRACTAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL
);




EXEC P_ALTERPK 'PK_T_ER_CONTRACTPROJECT', 'T_ER_CONTRACTPROJECT', 'FENTRYID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_CONTRACTPRO_FPROJECTNO') CREATE INDEX IDX_ER_CONTRACTPRO_FPROJECTNO ON T_ER_CONTRACTPROJECT ( FPROJECTNO );


EXEC P_ALTERPK 'PK_T_ER_CONTRACTPROJECT_LK', 'T_ER_CONTRACTPROJECT_LK', 'FPKID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_CONTRACTPROJECT_LK') CREATE INDEX IDX_ER_CONTRACTPROJECT_LK ON T_ER_CONTRACTPROJECT_LK ( FSBILLID );


EXEC P_ALTERPK 'PK_T_ER_APPLYPROJECTBILL_S', 'T_ER_APPLYPROJECTBILL_S', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_APPLYPROJECTBILL_S_FID') CREATE INDEX IDX_ER_APPLYPROJECTBILL_S_FID ON T_ER_APPLYPROJECTBILL_S ( FCONTRACTAMOUNT );


EXEC P_ALTERPK 'PK_T_ER_APPLYPROJECTENTRY_S', 'T_ER_APPLYPROJECTENTRY_S', 'FENTRYID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_APPLYPROJECTENTRY_S_FID') CREATE INDEX IDX_ER_APPLYPROJECTENTRY_S_FID ON T_ER_APPLYPROJECTENTRY_S ( FORIEXPCONTRACTAMOUNT );


