-- T_BGMD_DATALOCKCASE 规则执行方案主表
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BGMD_DATALOCKCASE') 
CREATE TABLE T_BGMD_DATALOCKCASE (
	FID             	BIGINT               NOT NULL DEFAULT 0,
	FMODELID            BIGINT               NOT NULL DEFAULT 0,
	FBUSINESSMODELID    BIGINT               NOT NULL DEFAULT 0,
	FENTITYVIEWID       BIGINT               NOT NULL DEFAULT 0,
	FDEFAULT      		CHAR(1)              NOT NULL DEFAULT '0',
	FNAME				NVARCHAR(500) 		 NOT NULL DEFAULT ' ',
	FCREATERID      	BIGINT               NOT NULL DEFAULT 0,
	FMODIFIERID      	BIGINT               NOT NULL DEFAULT 0,
	FCREATEDATE      	DATETIME             				   ,
	FMODIFYDATE      	DATETIME 
);

EXEC P_ALTERPK 'PK_BGMD_DATALOCKCASE', 'T_BGMD_DATALOCKCASE', 'FID', '1';
 
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_BGMD_DATALOCKCASE_P1')
CREATE INDEX IDX_BGMD_DATALOCKCASE_P1 ON T_BGMD_DATALOCKCASE (
FMODELID
);

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_BGMD_DATALOCKCASE_P2')
CREATE INDEX IDX_BGMD_DATALOCKCASE_P2 ON T_BGMD_DATALOCKCASE (
FBUSINESSMODELID
);

-- T_BGMD_DATALOCKCASEDETAIL 规则执行方案方案明细表
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BGMD_DATALOCKCASEDETAIL') 
CREATE TABLE T_BGMD_DATALOCKCASEDETAIL (
	FID             	BIGINT               NOT NULL DEFAULT 0,
	FCASEID    			BIGINT               NOT NULL DEFAULT 0,
	FENTITY             VARCHAR(500)         NOT NULL DEFAULT ' ',
	FPERIOD             VARCHAR(50)          NOT NULL DEFAULT ' '
);

EXEC P_ALTERPK 'PK_BGMD_DATALOCKCASEDETAIL', 'T_BGMD_DATALOCKCASEDETAIL', 'FID', '1';
 
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_BGMD_DATALOCKCASEDETAIL_P1')
CREATE INDEX IDX_BGMD_DATALOCKCASEDETAIL_P1 ON T_BGMD_DATALOCKCASEDETAIL (
FCASEID
);

 
 -- T_BGMD_DATALOCKCASE_AT 规则执行方案审计线索多选成员表
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BGMD_DATALOCKCASE_AT') 
CREATE TABLE T_BGMD_DATALOCKCASE_AT (
	FID             	BIGINT               NOT NULL DEFAULT 0,
	FPKID            	BIGINT               NOT NULL DEFAULT 0,
	FBASEDATAID    		BIGINT               NOT NULL DEFAULT 0
);

EXEC P_ALTERPK 'PK_BGMD_DATALOCKCASE_AT', 'T_BGMD_DATALOCKCASE_AT', 'FPKID', '1';
 
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_BGMD_DATALOCKCASE_AT_P1')
CREATE INDEX IDX_BGMD_DATALOCKCASE_AT_P1 ON T_BGMD_DATALOCKCASE_AT (
FID
);

 -- T_BGMD_DATALOCKCASE_BP 规则执行方案期间多选成员表
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BGMD_DATALOCKCASE_BP') 
CREATE TABLE T_BGMD_DATALOCKCASE_BP (
	FID             	BIGINT               NOT NULL DEFAULT 0,
	FPKID            	BIGINT               NOT NULL DEFAULT 0,
	FBASEDATAID    		BIGINT               NOT NULL DEFAULT 0
);

EXEC P_ALTERPK 'PK_BGMD_DATALOCKCASE_BP', 'T_BGMD_DATALOCKCASE_BP', 'FPKID', '1';
 
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_BGMD_DATALOCKCASE_BP_P1')
CREATE INDEX IDX_BGMD_DATALOCKCASE_BP_P1 ON T_BGMD_DATALOCKCASE_BP (
FID
);

 -- T_BGMD_DATALOCKCASE_DT 规则执行方案数据类型多选成员表
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BGMD_DATALOCKCASE_DT') 
CREATE TABLE T_BGMD_DATALOCKCASE_DT (
	FID             	BIGINT               NOT NULL DEFAULT 0,
	FPKID            	BIGINT               NOT NULL DEFAULT 0,
	FBASEDATAID    		BIGINT               NOT NULL DEFAULT 0
);

EXEC P_ALTERPK 'PK_BGMD_DATALOCKCASE_DT', 'T_BGMD_DATALOCKCASE_DT', 'FPKID', '1';
 
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_BGMD_DATALOCKCASE_DT_P1')
CREATE INDEX IDX_BGMD_DATALOCKCASE_DT_P1 ON T_BGMD_DATALOCKCASE_DT (
FID
);

 -- T_BGMD_DATALOCKCASE_V 规则执行方案版本多选成员表
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BGMD_DATALOCKCASE_V') 
CREATE TABLE T_BGMD_DATALOCKCASE_V (
	FID             	BIGINT               NOT NULL DEFAULT 0,
	FPKID            	BIGINT               NOT NULL DEFAULT 0,
	FBASEDATAID    		BIGINT               NOT NULL DEFAULT 0
);

EXEC P_ALTERPK 'PK_BGMD_DATALOCKCASE_V', 'T_BGMD_DATALOCKCASE_V', 'FPKID', '1';
 
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_BGMD_DATALOCKCASE_V_P1')
CREATE INDEX IDX_BGMD_DATALOCKCASE_V_P1 ON T_BGMD_DATALOCKCASE_V (
FID
);

