/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\EB_table.sql **/

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_APPLICATIONSCENARIO') 
 CREATE TABLE T_EB_APPLICATIONSCENARIO (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(50) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FMODELID BIGINT DEFAULT 0 NOT NULL,
FISSYSPRESET CHAR(1) DEFAULT '0' NOT NULL,
FDESCRIPTION NVARCHAR(1000) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_VIEWMEMBER') 
 CREATE TABLE T_EB_VIEWMEMBER (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(50) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FMODELID BIGINT DEFAULT 0 NOT NULL,
FMEMBERID BIGINT DEFAULT 0 NOT NULL,
FLONGNUMBER NVARCHAR(2000) DEFAULT ' ' NOT NULL,
FLEVEL INT DEFAULT 0 NOT NULL,
FDSEQ INT DEFAULT 0 NOT NULL,
FISLEAF CHAR(1) DEFAULT '1' NOT NULL,
FMEMBERSOURCE CHAR(1) DEFAULT '0' NOT NULL,
FPARENTID BIGINT DEFAULT 0 NOT NULL,
FDIMENSIONID BIGINT DEFAULT 0 NOT NULL,
FVIEWID BIGINT DEFAULT 0 NOT NULL,
FAGGOPRT CHAR(1) DEFAULT '0' NOT NULL,
FSTATUS CHAR(1) DEFAULT 'A' NOT NULL,
FENABLE CHAR(1) DEFAULT '1' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_DIMENSIONVIEW') 
 CREATE TABLE T_EB_DIMENSIONVIEW (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(50) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FMODELID BIGINT DEFAULT 0 NOT NULL,
FDESCRIPTION NVARCHAR(1000) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FDIMENSIONID BIGINT DEFAULT 0 NOT NULL,
FLEVEL INT DEFAULT 0 NOT NULL,
FDSEQ INT DEFAULT 0 NOT NULL,
FLONGNUMBER NVARCHAR(2000) DEFAULT ' ' NOT NULL,
FISLEAF CHAR(1) DEFAULT '1' NOT NULL,
FSOURCE CHAR(1) DEFAULT '0' NOT NULL,
FUSAGE  CHAR(1) DEFAULT ' ' NOT NULL,
FPARENTID BIGINT DEFAULT 0 NOT NULL,
FBASEVIEWID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_SCENARIOENTRY') 
 CREATE TABLE T_EB_SCENARIOENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FAPPSCENARIOID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_VIEWENTRY') 
 CREATE TABLE T_EB_VIEWENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FDIMENSIONID BIGINT DEFAULT 0 NOT NULL,
FVIEWID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_BUSINESSMODEL') 
 CREATE TABLE T_EB_BUSINESSMODEL (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(50) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FMODELID BIGINT DEFAULT 0 NOT NULL,
FISSYSPRESET CHAR(1) DEFAULT '0' NOT NULL,
FDESCRIPTION NVARCHAR(1000) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_PERIODVARIABLE') 
 CREATE TABLE T_EB_PERIODVARIABLE (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(50) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FDESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL,
FPERIODTYPE CHAR(1) DEFAULT '0' NOT NULL,
FOFFSET INT DEFAULT 0 NOT NULL,
FBASEVARIABLE BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FCREATER BIGINT DEFAULT 0 NOT NULL,
FMODIFIER BIGINT DEFAULT 0 NOT NULL
);

 EXEC p_DropIdx 'IDX_EB_FY_MODEL', 'T_EB_STRUCTOFFY';
  IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_FY_MODEL_NUMBER') CREATE UNIQUE INDEX IDX_EB_FY_MODEL_NUMBER ON T_EB_STRUCTOFFY ( FMODELID ,FNUMBER );
 
 EXEC p_DropIdx 'IDX_EB_PREIOD_MODEL', 'T_EB_STRUCTOFPERIOD';
  IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_PREIOD_MODEL_NUMBER') CREATE UNIQUE INDEX IDX_EB_PREIOD_MODEL_NUMBER ON T_EB_STRUCTOFPERIOD ( FMODELID ,FNUMBER );
 
 EXEC p_DropIdx 'IDX_EB_AT_MODEL', 'T_EB_STRUCTOFAUDITTRIAL';
  IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_AT_MODEL_NUMBER') CREATE UNIQUE INDEX IDX_EB_AT_MODEL_NUMBER ON T_EB_STRUCTOFAUDITTRIAL ( FMODELID ,FNUMBER );
 
 EXEC p_DropIdx 'IDX_EB_CURRENCY_MODEL', 'T_EB_STRUCTOFCURRENCY';
  IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_CUR_MODEL_NUMBER') CREATE UNIQUE INDEX IDX_EB_CUR_MODEL_NUMBER ON T_EB_STRUCTOFCURRENCY ( FMODELID ,FNUMBER );
 
 EXEC p_DropIdx 'IDX_EB_StructOfVersion_MODEL', 'T_EB_STRUCTOFVERSION';
  IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_VERSION_MODEL_NUMBER') CREATE UNIQUE INDEX IDX_EB_VERSION_MODEL_NUMBER ON T_EB_STRUCTOFVERSION ( FMODELID ,FNUMBER );
 
 EXEC p_DropIdx 'IDX_EB_METRIC_MODEL', 'T_EB_STRUCTOFMETRIC';
  IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_METRIC_MODEL_NUMBER') CREATE UNIQUE INDEX IDX_EB_METRIC_MODEL_NUMBER ON T_EB_STRUCTOFMETRIC ( FMODELID ,FNUMBER );
 
 EXEC p_DropIdx 'IDX_EB_CT_MODEL', 'T_EB_STRUCTOFCHANGETYPE';
 -- 变动类型不设置唯一索引  @袁立松
  IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_CT_MODEL_NUMBER') CREATE INDEX IDX_EB_CT_MODEL_NUMBER ON T_EB_STRUCTOFCHANGETYPE ( FMODELID ,FNUMBER );
 
 EXEC p_DropIdx 'IDX_EB_BPREIOD_MODEL', 'T_EB_STRUCTOFBPERIOD';
  IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_BPREIOD_MODEL_NUMBER') CREATE UNIQUE INDEX IDX_EB_BPREIOD_MODEL_NUMBER ON T_EB_STRUCTOFBPERIOD ( FMODELID ,FNUMBER );

 EXEC p_DropIdx 'IDX_EB_ACCOUNT_MODEL', 'T_EB_STRUCTOFACCOUNT';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_ACCOUNT_MODEL_NUMBER') CREATE UNIQUE INDEX IDX_EB_ACCOUNT_MODEL_NUMBER ON T_EB_STRUCTOFACCOUNT ( FMODELID ,FNUMBER );
 
 EXEC p_DropIdx 'IDX_EB_DateType_Model', 'T_EB_STRUCTOFDATETYPE';
  IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_DATETYPE_MODEL_NUMBER') CREATE UNIQUE INDEX IDX_EB_DATETYPE_MODEL_NUMBER ON T_EB_STRUCTOFDATETYPE ( FMODELID ,FNUMBER );
 
 EXEC p_DropIdx 'IDX_EB_ICENTITY_MODEL', 'T_EB_STRUCTOFICENTITY';
  IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_ICENTITY_MODEL_NUMBER') CREATE UNIQUE INDEX IDX_EB_ICENTITY_MODEL_NUMBER ON T_EB_STRUCTOFICENTITY ( FMODELID ,FNUMBER );

 EXEC p_DropIdx 'IDX_EB_ENT_MODEL', 'T_EB_STRUCTOFENT';
  IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_ENT_MODEL_NUMBER') CREATE UNIQUE INDEX IDX_EB_ENT_MODEL_NUMBER ON T_EB_STRUCTOFENT ( FMODELID ,FNUMBER );

 EXEC p_DropIdx 'IDX_EB_BP_MODEL', 'T_EB_STRUCTOFPROCESS';
  IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_BP_MODEL_NUMBER') CREATE UNIQUE INDEX IDX_EB_BP_MODEL_NUMBER ON T_EB_STRUCTOFPROCESS ( FMODELID ,FNUMBER );

 EXEC p_DropIdx 'IDX_EB_SCENE_MODEL', 'T_EB_STRUCTOFSCENE';
  IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_SCENE_MODEL_NUMBER') CREATE UNIQUE INDEX IDX_EB_SCENE_MODEL_NUMBER ON T_EB_STRUCTOFSCENE ( FMODELID ,FNUMBER );

 EXEC P_ALTERPK 'PK_T_EB_APPLICATIONSCENARIO', 'T_EB_APPLICATIONSCENARIO', 'FID', '1';

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


 EXEC P_ALTERPK 'PK_T_EB_VIEWMEMBER', 'T_EB_VIEWMEMBER', 'FID', '1';

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


 EXEC P_ALTERPK 'PK_T_EB_DIMENSIONVIEW', 'T_EB_DIMENSIONVIEW', 'FID', '1';

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


 EXEC P_ALTERPK 'PK_T_EB_SCENARIOENTRY', 'T_EB_SCENARIOENTRY', 'FENTRYID', '1';

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


 EXEC P_ALTERPK 'PK_T_EB_VIEWENTRY', 'T_EB_VIEWENTRY', 'FENTRYID', '1';

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


 EXEC P_ALTERPK 'PK_T_EB_BUSINESSMODEL', 'T_EB_BUSINESSMODEL', 'FID', '1';

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


 EXEC P_ALTERPK 'PK_T_EB_PERIODVARIABLE', 'T_EB_PERIODVARIABLE', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_PERIODVARIABLE_P1') CREATE INDEX IDX_EB_PERIODVARIABLE_P1 ON T_EB_PERIODVARIABLE ( FPERIODTYPE );


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