-- 结果表字段设置分录
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MSPLAN_RESULTFIELDENTRY_L')
 CREATE TABLE T_MSPLAN_RESULTFIELDENTRY_L (
FPKID NVARCHAR(36) DEFAULT ' ' NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FRESULTSRCFIELDNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
FRESULTDATATYPE NVARCHAR(255) DEFAULT ' ' NOT NULL,
FRESULTFIELDNAME NVARCHAR(255) DEFAULT ' ' NOT NULL
);

 EXEC P_ALTERPK 'PK_MSPLAN_RESULTFIELDENTRY_L', 'T_MSPLAN_RESULTFIELDENTRY_L', 'FPKID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_MSPLAN_RESULTFIELDENTRY_L') CREATE INDEX IDX_MSPLAN_RESULTFIELDENTRY_L ON T_MSPLAN_RESULTFIELDENTRY_L (FENTRYID ,FLOCALEID );
 
 -- 主表
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MSPLAN_CHECKRESOURCE_L' AND KSQL_COL_NAME ='FOPNAME') 
ALTER TABLE T_MSPLAN_CHECKRESOURCE_L ADD (FOPNAME NVARCHAR(255) DEFAULT ' ' NOT NULL);

-- 字段匹配信息分录
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MSPLAN_CHECKMATCHENTRY_L')
 CREATE TABLE T_MSPLAN_CHECKMATCHENTRY_L (
FPKID NVARCHAR(36) DEFAULT ' ' NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FSRCFIELDNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
FTARGETFIELDNAME NVARCHAR(255) DEFAULT ' ' NOT NULL
);

 EXEC P_ALTERPK 'PK_MSPLAN_CHECKMATCHENTRY_L', 'T_MSPLAN_CHECKMATCHENTRY_L', 'FPKID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_MSPLAN_CHECKMATCHENTRY_L') CREATE INDEX IDX_MSPLAN_CHECKMATCHENTRY_L ON T_MSPLAN_CHECKMATCHENTRY_L (FENTRYID ,FLOCALEID );

 -- 检查逻辑分录
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MSPLAN_CHECKLOGICENTRY_L')
 CREATE TABLE T_MSPLAN_CHECKLOGICENTRY_L (
FPKID NVARCHAR(36) DEFAULT ' ' NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FENTRYLEFTFIELDNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
FENTRYRIGHTFIELDNAME NVARCHAR(255) DEFAULT ' ' NOT NULL
);

 EXEC P_ALTERPK 'PK_MSPLAN_CHECKLOGICENTRY_L', 'T_MSPLAN_CHECKLOGICENTRY_L', 'FPKID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_MSPLAN_CHECKLOGICENTRY_L') CREATE INDEX IDX_MSPLAN_CHECKLOGICENTRY_L ON T_MSPLAN_CHECKLOGICENTRY_L (FENTRYID ,FLOCALEID );
 
 
