/**Begin D:\PDM_UPGRADE\PDM1\EB_table.sql **/

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_ENTITYBIZRECORD') 
CREATE TABLE T_EB_ENTITYBIZRECORD (
   FID                  BIGINT               NOT NULL DEFAULT 0,
   FENTITYID            BIGINT               NOT NULL DEFAULT 0,
   FSEQ                 INT                  NOT NULL DEFAULT 0,
   FCHANGETYPE          CHAR(1)              NOT NULL DEFAULT ' ',
   FEFFDATE             DATETIME             ,
   FEXPDATE             DATETIME             ,
   FMODIFIER            BIGINT               NOT NULL DEFAULT 0,
   FMODIFYTIME          DATETIME             
);
 
EXEC P_ALTERPK 'PK_T_EB_ENTITYBIZRECORD', 'T_EB_ENTITYBIZRECORD', 'FENTITYID', '1';
 
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_ENTITYBIZRECORD')
CREATE INDEX IDX_EB_ENTITYBIZRECORD ON T_EB_ENTITYBIZRECORD (
FID ASC
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_ENTITYNAMERECORD') 
CREATE TABLE T_EB_ENTITYNAMERECORD (
   FID                  BIGINT               NOT NULL DEFAULT 0,
   FENTITYID            BIGINT               NOT NULL DEFAULT 0,
   FSEQ                 INT                  NOT NULL DEFAULT 0,
   FEFFDATE             DATETIME             ,
   FEXPDATE             DATETIME             ,
   FMODIFIER            BIGINT               NOT NULL DEFAULT 0,
   FMODIFYTIME          DATETIME             
);

EXEC P_ALTERPK 'PK_T_EB_ENTITYNAMERECORD', 'T_EB_ENTITYNAMERECORD', 'FENTITYID', '1';


IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_ENTITYNAMERECORD')
CREATE INDEX IDX_EB_ENTITYNAMERECORD ON T_EB_ENTITYNAMERECORD (
FID ASC
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_ENTITYNAMERECORD_L') 
CREATE TABLE T_EB_ENTITYNAMERECORD_L (
   FPKID                VARCHAR(30)          NOT NULL DEFAULT ' ',
   FENTITYID            BIGINT               NOT NULL DEFAULT 0,
   FLOCALEID            VARCHAR(10)          NOT NULL DEFAULT ' ',
   FNAME                VARCHAR(255)         NOT NULL DEFAULT ' ',
   FSIMPLENAME          VARCHAR(100)         NOT NULL DEFAULT ' '
);

EXEC P_ALTERPK 'PK_T_EB_ENTITYNAMERECORD_L', 'T_EB_ENTITYNAMERECORD_L', 'FPKID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_ENTITYNAMERECORD_L')
CREATE INDEX IDX_EB_ENTITYNAMERECORD_L ON T_EB_ENTITYNAMERECORD_L (
FENTITYID ASC,
FLOCALEID ASC
);

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_ENTRECORD_L_FNAME')
CREATE INDEX IDX_EB_ENTRECORD_L_FNAME ON T_EB_ENTITYNAMERECORD_L (
FNAME ASC,
FENTITYID ASC
);


/**End D:\PDM_UPGRADE\PDM1\EB_table.sql **/
