/** 额度归口部门相关建表语句 **/

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_DEPTRELATION') 
 CREATE TABLE T_ER_DEPTRELATION (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FREIMDEPTID BIGINT DEFAULT 0 NOT NULL,
FDEPTID BIGINT DEFAULT 0 NOT NULL,
FREIMDEPTSTRUCTID BIGINT DEFAULT 0 NOT NULL,
FDEPTSTRUCTID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_REIMCTLDEPT_RELATION_L') 
 CREATE TABLE T_ER_REIMCTLDEPT_RELATION_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_ER_REIMCTLDEPT_RELATION') 
 CREATE TABLE T_ER_REIMCTLDEPT_RELATION (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(80) DEFAULT ' ' NOT NULL,
FSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FENABLE CHAR(1) DEFAULT ' ' NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FEXPENSEITEMID BIGINT DEFAULT 0 NOT NULL
);


/*创建索引,主键*/

 EXEC P_ALTERPK 'PK_T_ER_DEPTRELATION', 'T_ER_DEPTRELATION', 'FENTRYID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_DEPTRELATION_DEPTID') CREATE INDEX IDX_ER_DEPTRELATION_DEPTID ON T_ER_DEPTRELATION ( FDEPTID );

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


 EXEC P_ALTERPK 'PK_T_ER_REIMCTLDEPT_RELATION_L', 'T_ER_REIMCTLDEPT_RELATION_L', 'FPKID', '1';

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


 EXEC P_ALTERPK 'PK_T_ER_REIMCTLDEPT_RELATION', 'T_ER_REIMCTLDEPT_RELATION', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_DEPTRELATION_EXP') CREATE INDEX IDX_ER_DEPTRELATION_EXP ON T_ER_REIMCTLDEPT_RELATION ( FEXPENSEITEMID );




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