/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\EB_constraint.sql **/
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_BIZRULESET' AND KSQL_COL_NAME IN ('FEXECUTERANGE')) 
 ALTER TABLE T_EB_BIZRULESET ADD (FEXECUTERANGE NVARCHAR(10) DEFAULT ' ' NOT NULL );
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_MODEL' AND KSQL_COL_NAME IN ('FHASCACHE')) 
 ALTER TABLE T_EB_MODEL ADD (FHASCACHE CHAR(1) DEFAULT '0' NOT NULL );
 
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_BIZRULEGROUP' AND KSQL_COL_NAME ='FMODELID') 
 ALTER TABLE T_EB_BIZRULEGROUP ADD (FMODELID BIGINT DEFAULT 0 NOT NULL );
 
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_BIZRULECATALOG' AND KSQL_COL_NAME ='FISSYSTEM') 
 ALTER TABLE T_EB_BIZRULECATALOG ADD (FISSYSTEM CHAR(1) DEFAULT '0' NOT NULL );
 
  IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_TEMPLATE' AND KSQL_COL_NAME ='FDATASETID') 
 ALTER TABLE T_EB_TEMPLATE ADD (FDATASETID BIGINT DEFAULT 0 NOT NULL );

 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_STRUCTOFACCOUNT' AND KSQL_COL_NAME ='FCHANGETYPE') 
 ALTER TABLE T_EB_STRUCTOFACCOUNT ADD (FCHANGETYPE BIGINT DEFAULT 0 NOT NULL );
 
 
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_BIZRULEGROUP_L') 
 CREATE TABLE T_EB_BIZRULEGROUP_L (
FPKID NVARCHAR(30) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FNAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FLOCALEID NVARCHAR(10) DEFAULT ' ' NOT NULL
);
 
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_STRUCTOFPROCESS') 
 CREATE TABLE T_EB_STRUCTOFPROCESS (
FID BIGINT DEFAULT 0 NOT NULL,
FLONGNUMBER NVARCHAR(200) DEFAULT ' ' NOT NULL,
FMEMBERID BIGINT DEFAULT 0 NOT NULL,
FPARENTID BIGINT DEFAULT 0 NOT NULL,
FISLEAF CHAR(1) DEFAULT ' ' NOT NULL,
FLEVEL INT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FAGGOPRT CHAR(1) DEFAULT ' ' NOT NULL,
FDESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL,
FREFEREDSTATUS INT DEFAULT 0 NOT NULL,
FSTATUS VARCHAR(5) DEFAULT ' ' NOT NULL,
FENABLE VARCHAR(5) DEFAULT ' ' NOT NULL,
FDISABLERID BIGINT DEFAULT 0 NOT NULL,
FDISABLEDATE DATETIME,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FMODIFYTIME DATETIME,
FDIMENSIONID BIGINT DEFAULT 0 NOT NULL,
FMODELID BIGINT DEFAULT 0 NOT NULL,
FNAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FNUMBER NVARCHAR(50) DEFAULT ' ' NOT NULL,
FSIMPLENAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FMEMBERSOURCE CHAR(1) DEFAULT '0' NOT NULL,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FCOPYFROM BIGINT DEFAULT 0 NOT NULL,
FORGID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_STRUCTOFPROCESS_L') 
 CREATE TABLE T_EB_STRUCTOFPROCESS_L (
FPKID VARCHAR(30) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FDESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(200) DEFAULT ' ' NOT NULL,
FSIMPLENAME NVARCHAR(50) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_STRUCTOFSCENE') 
 CREATE TABLE T_EB_STRUCTOFSCENE (
FID BIGINT DEFAULT 0 NOT NULL,
FLONGNUMBER NVARCHAR(200) DEFAULT ' ' NOT NULL,
FMEMBERID BIGINT DEFAULT 0 NOT NULL,
FPARENTID BIGINT DEFAULT 0 NOT NULL,
FISLEAF CHAR(1) DEFAULT ' ' NOT NULL,
FLEVEL INT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FAGGOPRT CHAR(1) DEFAULT ' ' NOT NULL,
FENABLEHISREC CHAR(1) DEFAULT '1' NOT NULL,
FDESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL,
FSTATUS VARCHAR(5) DEFAULT ' ' NOT NULL,
FENABLE VARCHAR(5) DEFAULT ' ' NOT NULL,
FDISABLERID BIGINT DEFAULT 0 NOT NULL,
FDISABLEDATE DATETIME,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FMODIFYTIME DATETIME,
FORGID BIGINT DEFAULT 0 NOT NULL,
FDIMENSIONID BIGINT DEFAULT 0 NOT NULL,
FMODELID BIGINT DEFAULT 0 NOT NULL,
FNAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FNUMBER NVARCHAR(50) DEFAULT ' ' NOT NULL,
FSIMPLENAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FDCHANGETYPE CHAR(1) DEFAULT ' ' NOT NULL,
FMEMBERSOURCE CHAR(1) DEFAULT '0' NOT NULL,
FVALUE BIGINT DEFAULT 0 NOT NULL,
FCOPYFROM BIGINT DEFAULT 0 NOT NULL,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FDATATYPE CHAR(1) DEFAULT '0' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_STRUCTOFSCENE_L') 
 CREATE TABLE T_EB_STRUCTOFSCENE_L (
FPKID VARCHAR(30) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(200) DEFAULT ' ' NOT NULL,
FSIMPLENAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FDESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL
);

 
 EXEC p_DropIdx 'IDX_EB_BIZRULEGROUP_MO', 'T_EB_BIZRULEGROUP';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_BIZRULEGROUP_MO') CREATE INDEX IDX_EB_BIZRULEGROUP_MO ON T_EB_BIZRULEGROUP ( FMODELID );
 
 
 
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_DATETYPE_NUMBER') CREATE INDEX IDX_EB_DATETYPE_NUMBER ON T_EB_STRUCTOFDATETYPE ( FNUMBER );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_ICENTITY_MODEL') CREATE INDEX IDX_EB_ICENTITY_MODEL ON T_EB_STRUCTOFICENTITY ( FMODELID );

 EXEC P_ALTERPK 'PK_T_EB_STRUCTOFPROCESS', 'T_EB_STRUCTOFPROCESS', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_BP_MODEL') CREATE INDEX IDX_EB_BP_MODEL ON T_EB_STRUCTOFPROCESS ( FMODELID );

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

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_PROCESS_LONGNUM') CREATE INDEX IDX_EB_PROCESS_LONGNUM ON T_EB_STRUCTOFPROCESS ( FLONGNUMBER );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_BP_DIM') CREATE INDEX IDX_EB_BP_DIM ON T_EB_STRUCTOFPROCESS ( FDIMENSIONID );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_BP_PARENT') CREATE INDEX IDX_EB_BP_PARENT ON T_EB_STRUCTOFPROCESS ( FPARENTID );


 EXEC P_ALTERPK 'PK_T_EB_STRUCTOFPROCESS_L', 'T_EB_STRUCTOFPROCESS_L', 'FPKID', '1';

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

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_BP_L_NAME') CREATE INDEX IDX_EB_BP_L_NAME ON T_EB_STRUCTOFPROCESS_L ( FNAME ,FID );


 EXEC P_ALTERPK 'PK_T_EB_STRUCTOFSCENE', 'T_EB_STRUCTOFSCENE', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_SCENE_MODEL') CREATE INDEX IDX_EB_SCENE_MODEL ON T_EB_STRUCTOFSCENE ( FMODELID );

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

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_SCENE_LONGNUM') CREATE INDEX IDX_EB_SCENE_LONGNUM ON T_EB_STRUCTOFSCENE ( FLONGNUMBER );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_SCENE_DIM') CREATE INDEX IDX_EB_SCENE_DIM ON T_EB_STRUCTOFSCENE ( FDIMENSIONID );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_SCENE_PARENT') CREATE INDEX IDX_EB_SCENE_PARENT ON T_EB_STRUCTOFSCENE ( FPARENTID );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_ENT_PARENT') CREATE INDEX IDX_EB_ENT_PARENT ON T_EB_STRUCTOFENT ( FPARENTID );

 EXEC P_ALTERPK 'PK_T_EB_STRUCTOFSCENE_L', 'T_EB_STRUCTOFSCENE_L', 'FPKID', '1';

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

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_SCENE_L_NAME') CREATE INDEX IDX_EB_SCENE_L_NAME ON T_EB_STRUCTOFSCENE_L ( FNAME ,FID );

 
 EXEC P_ALTERPK 'PK_T_EB_BIZRULEGROUP_L', 'T_EB_BIZRULEGROUP_L', 'FPKID', '1';

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

/**End E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\EB_constraint.sql **/
