--用餐订单建表与索引sql
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_MEALBILL')
CREATE TABLE T_ER_MEALBILL (
   FID BIGINT DEFAULT 0 NOT NULL,
   FBILLNO VARCHAR(80) DEFAULT ' ' NOT NULL,
   FBILLSTATUS VARCHAR(50) DEFAULT ' ' NOT NULL,
   FCREATORID BIGINT DEFAULT 0 NOT NULL,
   FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
   FAUDITORID BIGINT DEFAULT 0 NOT NULL,
   FAUDITDATE DATETIME,
   FMODIFYTIME DATETIME,
   FCREATETIME DATETIME,
   FORGID BIGINT DEFAULT 0 NOT NULL,
   FSOURCEBOOKEDID BIGINT DEFAULT 0 NOT NULL,
   FSERVER VARCHAR(50) DEFAULT ' ' NOT NULL,
   FORDERDATE DATETIME,
   FORDERNUM VARCHAR(50) DEFAULT ' ' NOT NULL,
   FPARENTORDERNUM VARCHAR(50) DEFAULT ' ' NOT NULL,
   FORDERTYPE CHAR(1) DEFAULT ' ' NOT NULL,
   FOPERATIONTYPE CHAR(1) DEFAULT ' ' NOT NULL,
   FISBUSINESS CHAR(1) DEFAULT ' ' NOT NULL,
   FPRODUCTTYPE CHAR(1) DEFAULT ' ' NOT NULL,
   FHAPPENDDATE DATETIME,
   FOABILLNUM VARCHAR(80) DEFAULT ' ' NOT NULL,
   FREIMBURSENUM VARCHAR(80) DEFAULT ' ' NOT NULL,
   FORDERSTATUS VARCHAR(50) DEFAULT ' ' NOT NULL,
   FBOOKEDNAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
   FBOOKEDCOMPANY BIGINT DEFAULT 0 NOT NULL,
   FBOOKEDDEPT BIGINT DEFAULT 0 NOT NULL,
   FTOTALAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
   FMEALTIME DATETIME,
   FMEALCITYNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
   FDINNERSCENE CHAR(1) DEFAULT ' ' NOT NULL,
   FSERVICEFEE DECIMAL(23,10) DEFAULT 0 NOT NULL,
   FPERSONALFEE DECIMAL(23,10) DEFAULT 0 NOT NULL,
   FSHOPADDRESS NVARCHAR(255) DEFAULT ' ' NOT NULL,
   FSHOPNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
   FEXPCOMMITCOMNUM BIGINT DEFAULT 0 NOT NULL,
   FEXPCOMMITDEPNUM BIGINT DEFAULT 0 NOT NULL,
   FOVERDESC NVARCHAR(255) DEFAULT ' ' NOT NULL,
   FISCONFIRM CHAR(1) DEFAULT '0' NOT NULL,
   FISRECONCILIATION CHAR(1) DEFAULT '0' NOT NULL,
   FISAPPROVE CHAR(1) DEFAULT '0' NOT NULL,
   FCURRENCY BIGINT DEFAULT 0 NOT NULL,
   FNOTICETIMES INT DEFAULT 0 NOT NULL,
   FFEEDBACK NVARCHAR(255) DEFAULT ' ' NOT NULL,
   FCOMPANYID BIGINT DEFAULT 0 NOT NULL
);

EXEC P_ALTERPK 'PK_ER_MEALBILL', 'T_ER_MEALBILL', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_MBBILLNO') CREATE INDEX IDX_ER_MBBILLNO ON T_ER_MEALBILL ( FOABILLNUM );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_MBFSOURCEBOOKEDID') CREATE INDEX IDX_ER_MBFSOURCEBOOKEDID ON T_ER_MEALBILL ( FSOURCEBOOKEDID );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_MBILL_ORG') CREATE INDEX IDX_ER_MBILL_ORG ON T_ER_MEALBILL ( FEXPCOMMITCOMNUM ,FBOOKEDCOMPANY );
