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

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BGMD_DATALOCK') 
 CREATE TABLE T_BGMD_DATALOCK (
FID BIGINT DEFAULT 0 NOT NULL,
FMODELID BIGINT DEFAULT 0 NOT NULL,
FBUSINESSMODELID BIGINT DEFAULT 0 NOT NULL,
FYEARID BIGINT DEFAULT 0 NOT NULL,
FVERSIONID BIGINT DEFAULT 0 NOT NULL,
FDATATYPEID BIGINT DEFAULT 0 NOT NULL,
FAUDITTRAILID BIGINT DEFAULT 0 NOT NULL,
FREFSOURCE BIGINT DEFAULT 0 NOT NULL,
FENTITYNUMBER NVARCHAR(255) DEFAULT ' ' NOT NULL,
FPERIODINTEGER INT DEFAULT 0 NOT NULL
);

 EXEC P_ALTERPK 'PK_BGMD_DATALOCK', 'T_BGMD_DATALOCK', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_BGMD_DATALOCK_P1') CREATE INDEX IDX_BGMD_DATALOCK_P1 ON T_BGMD_DATALOCK ( FYEARID ,FVERSIONID ,FDATATYPEID,FAUDITTRAILID);

  IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_BGMD_DATALOCK_P2') CREATE INDEX IDX_BGMD_DATALOCK_P2 ON T_BGMD_DATALOCK ( FMODELID ,FBUSINESSMODELID );
 
/**End D:\PDM_UPGRADE\PDM1\EB_constraint.sql **/