
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_WRITEOFFSCHEME') 
 CREATE TABLE T_EB_WRITEOFFSCHEME (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(50) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FREMARK NVARCHAR(200) DEFAULT ' ' NOT NULL
);



IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_WRITEOFFINFOSELECT') 
 CREATE TABLE T_EB_WRITEOFFINFOSELECT (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FWRITEOFFBILL BIGINT DEFAULT 0 NOT NULL,
FWRITEOFFTYPE NVARCHAR(50) DEFAULT ' ' NOT NULL,
FWRITEOFFSOURCEBILL BIGINT DEFAULT 0 NOT NULL,
FWRITEOFFENTRY BIGINT DEFAULT 0 NOT NULL,
FWRITEOFFVALUE BIGINT DEFAULT 0 NOT NULL,
FWRITEOFFSOURCEBILLENTRY BIGINT DEFAULT 0 NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_WRITEOFFSCHEME' AND KSQL_COL_NAME IN ('FBILL'))
 ALTER TABLE T_EB_WRITEOFFSCHEME ADD (FBILL BIGINT DEFAULT 0 NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_BGCONPROCESSENTRY' AND KSQL_COL_NAME IN ('FWRITEOFFSCHEME')) 
 ALTER TABLE T_EB_BGCONPROCESSENTRY ADD (FWRITEOFFSCHEME BIGINT DEFAULT 0 NOT NULL );
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_BGCONPROCESSENTRY' AND KSQL_COL_NAME IN ('FWRITEOFFSCHEMECN')) 
 ALTER TABLE T_EB_BGCONPROCESSENTRY ADD (FWRITEOFFSCHEMECN NVARCHAR(50) DEFAULT ' ' NOT NULL );
 
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_WRITEOFFINFOSELECT' AND KSQL_COL_NAME IN ('FWRITEOFFSOURCEBILLENTRY'))
ALTER TABLE T_EB_WRITEOFFINFOSELECT  ADD (FWRITEOFFSOURCEBILLENTRY BIGINT DEFAULT 0 NOT NULL );

EXEC P_ALTERPK 'PK_T_EB_WRITEOFFSCHEME', 'T_EB_WRITEOFFSCHEME', 'FID', '1';
EXEC P_ALTERPK 'PK_T_EB_WRITEOFFINFOSELECT', 'T_EB_WRITEOFFINFOSELECT', 'FENTRYID', '1';


/**Begin D:\PDM_UPGRADE\PDM1\EB_constraint.sql **/

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CENTRALAPPRECENTITY' AND KSQL_COL_NAME ='FAPPROVEPLANS') 
 ALTER TABLE T_EB_CENTRALAPPRECENTITY ADD (FAPPROVEPLANS NVARCHAR(255) DEFAULT ' ' NOT NULL);
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CENTRALAPPADJRECORD' AND KSQL_COL_NAME ='FDIM1') 
 ALTER TABLE T_EB_CENTRALAPPADJRECORD ADD (FDIM1 NVARCHAR(100) DEFAULT ' ' NOT NULL);
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CENTRALAPPADJRECORD' AND KSQL_COL_NAME ='FDIM2') 
 ALTER TABLE T_EB_CENTRALAPPADJRECORD ADD (FDIM2 NVARCHAR(100) DEFAULT ' ' NOT NULL);
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CENTRALAPPADJRECORD' AND KSQL_COL_NAME ='FDIM3') 
 ALTER TABLE T_EB_CENTRALAPPADJRECORD ADD (FDIM3 NVARCHAR(100) DEFAULT ' ' NOT NULL);
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CENTRALAPPADJRECORD' AND KSQL_COL_NAME ='FDIM4') 
 ALTER TABLE T_EB_CENTRALAPPADJRECORD ADD (FDIM4 NVARCHAR(100) DEFAULT ' ' NOT NULL);
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CENTRALAPPADJRECORD' AND KSQL_COL_NAME ='FDIM5') 
 ALTER TABLE T_EB_CENTRALAPPADJRECORD ADD (FDIM5 NVARCHAR(100) DEFAULT ' ' NOT NULL);
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CENTRALAPPADJRECORD' AND KSQL_COL_NAME ='FDIM6') 
 ALTER TABLE T_EB_CENTRALAPPADJRECORD ADD (FDIM6 NVARCHAR(100) DEFAULT ' ' NOT NULL);
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CENTRALAPPADJRECORD' AND KSQL_COL_NAME ='FDIM7') 
 ALTER TABLE T_EB_CENTRALAPPADJRECORD ADD (FDIM7 NVARCHAR(100) DEFAULT ' ' NOT NULL);
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CENTRALAPPADJRECORD' AND KSQL_COL_NAME ='FDIM8') 
 ALTER TABLE T_EB_CENTRALAPPADJRECORD ADD (FDIM8 NVARCHAR(100) DEFAULT ' ' NOT NULL);
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CENTRALAPPADJRECORD' AND KSQL_COL_NAME ='FDIM9') 
 ALTER TABLE T_EB_CENTRALAPPADJRECORD ADD (FDIM9 NVARCHAR(100) DEFAULT ' ' NOT NULL);
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CENTRALAPPADJRECORD' AND KSQL_COL_NAME ='FDIM10') 
 ALTER TABLE T_EB_CENTRALAPPADJRECORD ADD (FDIM10 NVARCHAR(100) DEFAULT ' ' NOT NULL);
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CENTRALAPPADJRECORD' AND KSQL_COL_NAME ='FDIM11') 
 ALTER TABLE T_EB_CENTRALAPPADJRECORD ADD (FDIM11 NVARCHAR(100) DEFAULT ' ' NOT NULL);
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CENTRALAPPADJRECORD' AND KSQL_COL_NAME ='FDIM12') 
 ALTER TABLE T_EB_CENTRALAPPADJRECORD ADD (FDIM12 NVARCHAR(100) DEFAULT ' ' NOT NULL);
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CENTRALAPPADJRECORD' AND KSQL_COL_NAME ='FDIM13') 
 ALTER TABLE T_EB_CENTRALAPPADJRECORD ADD (FDIM13 NVARCHAR(100) DEFAULT ' ' NOT NULL);
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CENTRALAPPADJRECORD' AND KSQL_COL_NAME ='FDIM14') 
 ALTER TABLE T_EB_CENTRALAPPADJRECORD ADD (FDIM14 NVARCHAR(100) DEFAULT ' ' NOT NULL);
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CENTRALAPPADJRECORD' AND KSQL_COL_NAME ='FDIM15') 
 ALTER TABLE T_EB_CENTRALAPPADJRECORD ADD (FDIM15 NVARCHAR(100) DEFAULT ' ' NOT NULL);
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CENTRALAPPADJRECORD' AND KSQL_COL_NAME ='FDIM16') 
 ALTER TABLE T_EB_CENTRALAPPADJRECORD ADD (FDIM16 NVARCHAR(100) DEFAULT ' ' NOT NULL);
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CENTRALAPPADJRECORD' AND KSQL_COL_NAME ='FDIM17') 
 ALTER TABLE T_EB_CENTRALAPPADJRECORD ADD (FDIM17 NVARCHAR(100) DEFAULT ' ' NOT NULL);
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CENTRALAPPADJRECORD' AND KSQL_COL_NAME ='FDIM18') 
 ALTER TABLE T_EB_CENTRALAPPADJRECORD ADD (FDIM18 NVARCHAR(100) DEFAULT ' ' NOT NULL);
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CENTRALAPPADJRECORD' AND KSQL_COL_NAME ='FAPPROVEPLANS') 
 ALTER TABLE T_EB_CENTRALAPPADJRECORD ADD (FAPPROVEPLANS NVARCHAR(255) DEFAULT ' ' NOT NULL);
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CENTRALAPPADJRECORD' AND KSQL_COL_NAME ='FCENTRALSCHEMES') 
 ALTER TABLE T_EB_CENTRALAPPADJRECORD ADD (FCENTRALSCHEMES NVARCHAR(255) DEFAULT ' ' NOT NULL);
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CENTRALAPPADJRECORD' AND KSQL_COL_NAME ='FAPPROVER') 
 ALTER TABLE T_EB_CENTRALAPPADJRECORD ADD (FAPPROVER BIGINT DEFAULT 0 NOT NULL);
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CENTRALAPPADJRECORD' AND KSQL_COL_NAME ='FORG') 
 ALTER TABLE T_EB_CENTRALAPPADJRECORD ADD (FORG BIGINT DEFAULT 0 NOT NULL);
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CENTRALAPPADJRECORD' AND KSQL_COL_NAME ='FAPPROVEDATE') 
 ALTER TABLE T_EB_CENTRALAPPADJRECORD ADD (FAPPROVEDATE DATETIME);
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_CENTRALAPPADJRECORD' AND KSQL_COL_NAME ='FADJUSTTYPE') 
 ALTER TABLE T_EB_CENTRALAPPADJRECORD ADD (FADJUSTTYPE CHAR(1) DEFAULT '1' NOT NULL);
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_CENTRALAPPADJ_ENTITY') 
 CREATE TABLE T_EB_CENTRALAPPADJ_ENTITY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FCOLKEY NVARCHAR(50) DEFAULT ' ' NOT NULL,
FCOLTYPE CHAR(1) DEFAULT '0' NOT NULL,
FDIMRANGE NCLOB,
FPREADJUST NVARCHAR(255) DEFAULT ' ' NOT NULL,
FAFTERADJUST NVARCHAR(255) DEFAULT ' ' NOT NULL,
FDIMRANGEHASH NVARCHAR(100) DEFAULT ' ' NOT NULL
);

/**End D:\PDM_UPGRADE\PDM1\EB_constraint.sql **/
