IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_TASKTRANSFER_RECORD') 
 CREATE TABLE T_EB_TASKTRANSFER_RECORD (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(30) DEFAULT ' ' NOT NULL,
FMODEL BIGINT DEFAULT 0,
FPERIOD BIGINT DEFAULT 0,
FEXECUTOR BIGINT DEFAULT 0 NOT NULL,
FTRANSFERUSER BIGINT DEFAULT 0 NOT NULL,
FTRANSFERDATE DATETIME,
FTRANSFERREASON NVARCHAR(255) DEFAULT ' ',
FBILLSTATUS NVARCHAR(50) DEFAULT ' ' NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_TASKTRANSFER_RECORD_L') 
 CREATE TABLE T_EB_TASKTRANSFER_RECORD_L (
FID BIGINT DEFAULT 0 NOT NULL,
FPKID NVARCHAR(50) DEFAULT ' ' NOT NULL,
FLOCALEID NVARCHAR(10) DEFAULT ' ' NOT NULL,
FTRANSFERREASON NVARCHAR(255) DEFAULT ' ' NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_TASKTRANSFER_DETAIL') 
 CREATE TABLE T_EB_TASKTRANSFER_DETAIL (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FTASK BIGINT DEFAULT 0,
FENTITY BIGINT DEFAULT 0,
FTASKPACKAGE BIGINT DEFAULT 0,
FTASKSTATE NVARCHAR(50) DEFAULT ' ',
FSTARTDATE DATETIME,
FENDDATE DATETIME
);

EXEC P_ALTERPK 'PK_T_EB_TASKTRANSFER_RECORD', 'T_EB_TASKTRANSFER_RECORD', 'FID', '1';

EXEC P_ALTERPK 'PK_T_EB_TASKTRANSFER_RECORD_L', 'T_EB_TASKTRANSFER_RECORD_L', 'FPKID', '1';

EXEC P_ALTERPK 'PK_T_EB_TASKTRANSFER_DETAIL', 'T_EB_TASKTRANSFER_DETAIL', 'FENTRYID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_T_EB_TASKTRANSFER_RECORD_L') CREATE INDEX IDX_T_EB_TASKTRANSFER_RECORD_L ON T_EB_TASKTRANSFER_RECORD_L ( FID );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_T_EB_TASKTRANSFER_DETAIL') CREATE INDEX IDX_T_EB_TASKTRANSFER_DETAIL ON T_EB_TASKTRANSFER_DETAIL ( FID );