/**Begin 创建发票云打印影像模板 **/

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_IMAGE_TPLUSEREG') 
 CREATE TABLE T_ER_IMAGE_TPLUSEREG (
FUSEORGID BIGINT DEFAULT 0 NOT NULL,
FDATAID BIGINT DEFAULT 0 NOT NULL,
FCREATEORGID BIGINT DEFAULT 0 NOT NULL,
FADMINORGID BIGINT DEFAULT 0 NOT NULL,
FCTRLSTRATEGY VARCHAR(30) DEFAULT ' ' NOT NULL,
FISASSIGN CHAR(1) DEFAULT ' ' NOT NULL,
FASSIGNORGID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_PRINT_TPL_ENTRY') 
 CREATE TABLE T_ER_PRINT_TPL_ENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FENTITYMETA VARCHAR(50) DEFAULT ' ' NOT NULL,
FPRINTTPL VARCHAR(50) DEFAULT ' ' NOT NULL
);



IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_IMAGE_TPL') 
 CREATE TABLE T_ER_IMAGE_TPL (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER VARCHAR(30) DEFAULT ' ' NOT NULL,
FSTATUS CHAR(1) DEFAULT 'A' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FENABLE CHAR(1) DEFAULT '1' NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FCREATEORGID BIGINT DEFAULT 0 NOT NULL,
FORGID BIGINT DEFAULT 0 NOT NULL,
FCTRLSTRATEGY VARCHAR(30) DEFAULT '5' NOT NULL,
FBIZAPPID VARCHAR(50) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_IMAGE_TPL_R3') 
 CREATE TABLE T_ER_IMAGE_TPL_R3 (
FID BIGINT DEFAULT 0 NOT NULL,
FREFSTATUS CHAR(1) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_IMAGE_TPL_U') 
 CREATE TABLE T_ER_IMAGE_TPL_U (
FDATAID BIGINT DEFAULT 0 NOT NULL,
FCREATEORGID BIGINT DEFAULT 0 NOT NULL,
FUSEORGID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_IMAGE_TPLEXC') 
 CREATE TABLE T_ER_IMAGE_TPLEXC (
FDATAID BIGINT DEFAULT 0 NOT NULL,
FCREATEORGID BIGINT DEFAULT 0 NOT NULL,
FUSEORGID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_IMAGE_TPL_L') 
 CREATE TABLE T_ER_IMAGE_TPL_L (
FPKID VARCHAR(36) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL
);


/*创建对应的主键和索引*/
 EXEC P_ALTERPK 'PK_T_ER_IMAGE_TPLUSEREG', 'T_ER_IMAGE_TPLUSEREG', 'FUSEORGID,FDATAID', '0';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_IMAGE_TPLUSEREG_DATAID') CREATE  CLUSTERED INDEX IDX_ER_IMAGE_TPLUSEREG_DATAID ON T_ER_IMAGE_TPLUSEREG ( FDATAID );


 EXEC P_ALTERPK 'PK_T_ER_PRINT_TPL_ENTRY', 'T_ER_PRINT_TPL_ENTRY', 'FENTRYID', '0';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_PRINT_TPL_ENTRY') CREATE UNIQUE  CLUSTERED INDEX IDX_ER_PRINT_TPL_ENTRY ON T_ER_PRINT_TPL_ENTRY ( FID ,FENTITYMETA );



 EXEC P_ALTERPK 'PK_T_ER_IMAGE_TPL', 'T_ER_IMAGE_TPL', 'FID', '0';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_IMAGE_TPL_FAPPID') CREATE  CLUSTERED INDEX IDX_ER_IMAGE_TPL_FAPPID ON T_ER_IMAGE_TPL ( FBIZAPPID );


 EXEC P_ALTERPK 'PK_T_ER_IMAGE_TPL_R3', 'T_ER_IMAGE_TPL_R3', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_IMAGE_TPL_R3') CREATE INDEX IDX_ER_IMAGE_TPL_R3 ON T_ER_IMAGE_TPL_R3 ( FREFSTATUS );


 EXEC P_ALTERPK 'PK_T_ER_IMAGE_TPL_U', 'T_ER_IMAGE_TPL_U', 'FDATAID,FUSEORGID', '0';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_IMAGE_TPL_U') CREATE  CLUSTERED INDEX IDX_ER_IMAGE_TPL_U ON T_ER_IMAGE_TPL_U ( FCREATEORGID );


 EXEC P_ALTERPK 'PK_T_ER_IMAGE_TPLEXC', 'T_ER_IMAGE_TPLEXC', 'FDATAID,FUSEORGID', '0';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_IMAGE_TPLEXC_DATAID') CREATE  CLUSTERED INDEX IDX_IMAGE_TPLEXC_DATAID ON T_ER_IMAGE_TPLEXC ( FCREATEORGID );

 EXEC P_ALTERPK 'PK_T_ER_IMAGE_TPL_L', 'T_ER_IMAGE_TPL_L', 'FPKID', '0';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_IMAGE_TPL_L') CREATE  CLUSTERED INDEX IDX_ER_IMAGE_TPL_L ON T_ER_IMAGE_TPL_L ( FID ,FLOCALEID );



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