/**Begin C:\PDM_UPGRADE\PDM1\PUR_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PUR_CALFORMULA') 
 CREATE TABLE T_PUR_CALFORMULA (
FID BIGINT DEFAULT 0 NOT NULL,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(80) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FFORMULAPREVIEW NVARCHAR(1000) DEFAULT ' ' NOT NULL,
FFORMULA NVARCHAR(500) DEFAULT ' ',
FPLUGINNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
FSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FCALMETHOD CHAR(1) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FMODIFYTIME DATETIME,
FAUDITORID BIGINT DEFAULT 0 NOT NULL,
FAUDITDATE DATETIME,
FDISABLERID BIGINT DEFAULT 0 NOT NULL,
FDISABLEDATE DATETIME,
FENABLE CHAR(1) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PUR_CALFORMULA_L') 
 CREATE TABLE T_PUR_CALFORMULA_L (
FPKID VARCHAR(36) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PUR_CALFORMULAENTITY') 
 CREATE TABLE T_PUR_CALFORMULAENTITY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FMETADATAID VARCHAR(50) DEFAULT ' ' NOT NULL,
FCHILDFORMULA NVARCHAR(500) DEFAULT ' ' NOT NULL,
FCHILDFORMULATRAN NVARCHAR(1000) DEFAULT ' ' NOT NULL,
FBEFOREFILTER NVARCHAR(500) DEFAULT ' ' NOT NULL,
FBEFOREFILTERTRAN NVARCHAR(1000) DEFAULT ' ' NOT NULL,
FAFTERFILTER NVARCHAR(500) DEFAULT ' ' NOT NULL,
FAFTERFILTERTRAN NVARCHAR(1000) DEFAULT ' ' NOT NULL,
FORGFIELD VARCHAR(50) DEFAULT ' ' NOT NULL,
FSUPPLIERFIELD VARCHAR(50) DEFAULT ' ' NOT NULL,
FMATERIALFIELD VARCHAR(50) DEFAULT ' ' NOT NULL,
FEVALPERIODFIELD VARCHAR(50) DEFAULT ' ' NOT NULL,
FGROUPBY NVARCHAR(255) DEFAULT ' ' NOT NULL,
FENTITYCODE VARCHAR(50) DEFAULT ' ' NOT NULL,
FEVADIMENSIONFILTER CHAR(1) DEFAULT 'A' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PUR_CALRESULT') 
 CREATE TABLE T_PUR_CALRESULT (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
FBILLSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FMODIFYTIME DATETIME,
FAUDITORID BIGINT DEFAULT 0 NOT NULL,
FAUDITDATE DATETIME,
FORGID BIGINT DEFAULT 0 NOT NULL,
FSRMINDEX BIGINT DEFAULT 0 NOT NULL,
FCALFORMULA BIGINT DEFAULT 0 NOT NULL,
FEVAPLANID BIGINT DEFAULT 0 NOT NULL,
FEVAPLANNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FDATEFROM DATETIME,
FDATETO DATETIME,
FEVADIMENSION CHAR(1) DEFAULT ' ' NOT NULL,
FFORMULA NVARCHAR(500) DEFAULT ' ' NOT NULL,
FFORMULATRAN NVARCHAR(1000) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PUR_CALRESULTENTITY') 
 CREATE TABLE T_PUR_CALRESULTENTITY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FSUPPLIERID BIGINT DEFAULT 0 NOT NULL,
FMATERIALID BIGINT DEFAULT 0 NOT NULL,
FSCORETASKID BIGINT DEFAULT 0 NOT NULL,
FINDEXSCOREDETAILID BIGINT DEFAULT 0 NOT NULL,
FRESULT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FRESULT1 DECIMAL(23,10) DEFAULT 0 NOT NULL,
FRESULT2 DECIMAL(23,10) DEFAULT 0 NOT NULL,
FRESULT3 DECIMAL(23,10) DEFAULT 0 NOT NULL,
FRESULT4 DECIMAL(23,10) DEFAULT 0 NOT NULL,
FRESULT5 DECIMAL(23,10) DEFAULT 0 NOT NULL
);



/**End C:\PDM_UPGRADE\PDM1\PUR_table.sql **/
/**Begin C:\PDM_UPGRADE\PDM1\PUR_constraint.sql **/
 EXEC P_ALTERPK 'PK_T_PUR_CALFORMULA', 'T_PUR_CALFORMULA', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_PUR_CALFORMULA_FNUMBER') CREATE INDEX IDX_PUR_CALFORMULA_FNUMBER ON T_PUR_CALFORMULA ( FNUMBER );


 EXEC P_ALTERPK 'PK_PUR_CALFORMULA_L', 'T_PUR_CALFORMULA_L', 'FPKID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_PUR_CALFORMULA_L_FID_FLID') CREATE INDEX IDX_PUR_CALFORMULA_L_FID_FLID ON T_PUR_CALFORMULA_L ( FID ,FLOCALEID );


 EXEC P_ALTERPK 'PK_PUR_CALFORMULAENTITY', 'T_PUR_CALFORMULAENTITY', 'FENTRYID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_CALFORMULAENTITY_FID_FSEQ') CREATE INDEX IDX_CALFORMULAENTITY_FID_FSEQ ON T_PUR_CALFORMULAENTITY ( FID ,FSEQ );


 EXEC P_ALTERPK 'PK_PUR_CALRESULT', 'T_PUR_CALRESULT', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_PUR_CALRESULT_CLUSTER') CREATE INDEX IDX_PUR_CALRESULT_CLUSTER ON T_PUR_CALRESULT ( FORGID ,FSRMINDEX ,FEVAPLANID ,FEVADIMENSION );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_PUR_CALRESULT_FBILLNO') CREATE INDEX IDX_PUR_CALRESULT_FBILLNO ON T_PUR_CALRESULT ( FBILLNO );


 EXEC P_ALTERPK 'PK_PUR_CALRESULTENTITY', 'T_PUR_CALRESULTENTITY', 'FENTRYID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_PUR_CALRESULTE_FID_FSEQ') CREATE INDEX IDX_PUR_CALRESULTE_FID_FSEQ ON T_PUR_CALRESULTENTITY ( FID ,FSEQ );



/**End C:\PDM_UPGRADE\PDM1\PUR_constraint.sql **/
