/**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_MEMBPERMRECORD') 
CREATE TABLE T_EB_MEMBPERMRECORD (
FID BIGINT DEFAULT 0 NOT NULL,
FMODELID BIGINT DEFAULT 0 NOT NULL,
FDIMENSIONID BIGINT DEFAULT 0 NOT NULL,
FUID BIGINT DEFAULT 0 NOT NULL,
FBIZCTRLRANGEID BIGINT DEFAULT 0 NOT NULL,
FMODIFIER BIGINT DEFAULT 0 NOT NULL,
FMODIFYTIME DATETIME,
FPERMGROUP CHAR(1) DEFAULT '0' NOT NULL
);

-- 维度成员权限子表
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_MEMBPERMRECORDDETAIL') 
CREATE TABLE T_EB_MEMBPERMRECORDDETAIL (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FMEMBERID BIGINT DEFAULT 0 NOT NULL,
FPERMVAL SMALLINT NOT NULL DEFAULT 0,
FSEQ INT NOT NULL DEFAULT 0
);

-- 主键
EXEC P_ALTERPK 'PK_T_EB_MEMBPERMRECORD', 'T_EB_MEMBPERMRECORD', 'FID', '1';
EXEC P_ALTERPK 'PK_T_EB_MEMBPERMRECORDDETAIL', 'T_EB_MEMBPERMRECORDDETAIL', 'FENTRYID', '1';

-- 索引
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IX_EB_MEMBPERMRECORD')
CREATE INDEX IX_EB_MEMBPERMRECORD ON T_EB_MEMBPERMRECORD ( FDIMENSIONID, FBIZCTRLRANGEID, FUID, FPERMGROUP );
-- 基于fid
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IX_EB_MEMBPERMRECORDDETAIL')
CREATE INDEX IX_EB_MEMBPERMRECORDDETAIL ON T_EB_MEMBPERMRECORDDETAIL (FID);
-- 基于成员id
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IX_EB_MEMBPERMRECORDDETAIL1')
CREATE INDEX IX_EB_MEMBPERMRECORDDETAIL1 ON T_EB_MEMBPERMRECORDDETAIL (FMEMBERID);

/**END E:\NEXTERP_PDM\PDM_UPGRADE\PDMS\BRANCH_LASTEST\PDM\EB_TABLE.SQL **/