
/*交通工具*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_VEHICLE')
 CREATE TABLE T_ER_VEHICLE (
FID BIGINT DEFAULT 0 NOT NULL,
FNAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FDESCRIPTION  NVARCHAR(50) DEFAULT ' ' NOT NULL,
FISPRESET CHAR(1) DEFAULT ' ' NOT NULL,
FMODIFYTIME DATETIME,
FSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FENABLE CHAR(1) DEFAULT ' ' NOT NULL,
FTRIPCONTROL VARCHAR(2) DEFAULT ' ' NOT NULL,
FNUMBER NVARCHAR(30) DEFAULT ' ' NOT NULL,
FATTRIBUTE CHAR(1) DEFAULT ' ' NOT NULL

);



 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_VEHICLE' AND KSQL_COL_NAME ='FTRIPCONTROL')
 ALTER TABLE T_ER_VEHICLE ADD (FTRIPCONTROL VARCHAR(2) DEFAULT ' ' NOT NULL );


 EXEC P_ALTERPK 'PK_T_ER_VEHICLE', 'T_ER_VEHICLE', 'FID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_VEHICLE_FATTRIBUTE') CREATE INDEX IDX_ER_VEHICLE_FATTRIBUTE ON T_ER_VEHICLE ( FATTRIBUTE );


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

 EXEC P_ALTERPK 'PK_T_ER_VEHICLE_L', 'T_ER_VEHICLE_L', 'FPKID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_VEHICLE_L_FLCID') CREATE INDEX IDX_ER_VEHICLE_L_FLCID ON T_ER_VEHICLE_L ( FID ,FLOCALEID );


/*座位等级*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_SEATGRADE' AND KSQL_COL_NAME IN ('FISPRESET'))
 ALTER TABLE T_ER_SEATGRADE ADD (FISPRESET CHAR(1) DEFAULT '0' NOT NULL);
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_SEATGRADE' AND KSQL_COL_NAME IN ('FGROUPID'))
 ALTER TABLE T_ER_SEATGRADE ADD (FGROUPID BIGINT DEFAULT 0 NOT NULL);
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_SEATGRADE' AND KSQL_COL_NAME IN ('FDESCRIPTION'))
 ALTER TABLE T_ER_SEATGRADE ADD (FDESCRIPTION NVARCHAR(50) DEFAULT ' ' NOT NULL);

/** 交通工具标准 */

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_TRIP_VEH_STAND')
CREATE TABLE T_ER_TRIP_VEH_STAND
(
 FID  BIGINT          DEFAULT 0   NOT NULL,
FSTARDARDTYPE     BIGINT          DEFAULT 0   NOT NULL,
FORGID BIGINT          DEFAULT 0   NOT NULL,
FSRCCREATEORGID BIGINT          DEFAULT 0   NOT NULL,
FMODIFYTIME DATETIME,
FSTATUS  VARCHAR(1)     DEFAULT ' ' NOT NULL,
FCREATORID BIGINT          DEFAULT 0   NOT NULL,
FMASTERID BIGINT          DEFAULT 0   NOT NULL,
FSOURCEDATAID BIGINT          DEFAULT 0   NOT NULL,
FEFFECTIVEDATE DATETIME,
FBITINDEX BIGINT          DEFAULT 0   NOT NULL,
FCONTROL  CHAR(1)         DEFAULT ' ' NOT NULL,
FVEHICLE BIGINT          DEFAULT 0   NOT NULL,
FCREATEORGID BIGINT          DEFAULT 0   NOT NULL,
FNAME NVARCHAR(100)   DEFAULT ' ' NOT NULL,
FMODIFIERID BIGINT          DEFAULT 0   NOT NULL,
FCREATETIME DATETIME,
FDESCRIPTION NVARCHAR(50)  DEFAULT ' ' NOT NULL,
FCTRLSTRATEGY VARCHAR(50)     DEFAULT ' ' NOT NULL,
FENABLE VARCHAR(1)     DEFAULT ' ' NOT NULL,
FNUMBER VARCHAR(100)    DEFAULT ' ' NOT NULL,
FSOURCEBITINDEX BIGINT          DEFAULT 0   NOT NULL,
FDIMENSION NVARCHAR(2000)  DEFAULT ' ' NOT NULL

);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_TRIP_VEH_STAND_L')
CREATE TABLE T_ER_TRIP_VEH_STAND_L(
    FID       BIGINT        DEFAULT 0   NOT NULL,
    FPKID     NVARCHAR(50)  DEFAULT ' ' NOT NULL,
    FNAME     NVARCHAR(200) DEFAULT ' ' NOT NULL,
    FLOCALEID NVARCHAR(50)  DEFAULT ' ' NOT NULL
);



IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_VEH_TRIPTYPE')
CREATE TABLE T_ER_VEH_TRIPTYPE(
    FID         BIGINT DEFAULT 0 NOT NULL,
    FPKID       BIGINT DEFAULT 0 NOT NULL,
    FBASEDATAID BIGINT DEFAULT 0 NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_VEH_REIMBURSELEVEL')
CREATE TABLE T_ER_VEH_REIMBURSELEVEL
(
    FID         BIGINT DEFAULT 0 NOT NULL,
    FPKID       BIGINT DEFAULT 0 NOT NULL,
    FBASEDATAID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_VEH_SEAT_ENTRY')
CREATE TABLE T_ER_VEH_SEAT_ENTRY(
    FID         BIGINT DEFAULT 0 NOT NULL,
    FSEAT       BIGINT DEFAULT 0 NOT NULL,
    FENTRYID       BIGINT DEFAULT 0 NOT NULL,
    FSEQ INT DEFAULT 0 NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_VEH_SEAT')
CREATE TABLE T_ER_VEH_SEAT
(
    FID         BIGINT DEFAULT 0 NOT NULL,
    FPKID       BIGINT DEFAULT 0 NOT NULL,
    FBASEDATAID BIGINT DEFAULT 0 NOT NULL
);

/**主键及索引相关改动**/
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_TRIP_VEH_STAND_NUMBER')
CREATE INDEX IDX_ER_TRIP_VEH_STAND_NUMBER ON T_ER_TRIP_VEH_STAND (FNUMBER);

EXEC P_ALTERPK 'PK_T_ER_TRIP_VEH_STAND', 'T_ER_TRIP_VEH_STAND', 'FID', '1';

EXEC P_ALTERPK 'PK_T_ER_TRIP_VEH_STAND_L', 'T_ER_TRIP_VEH_STAND_L', 'FPKID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_TRIP_VEHICLE_STANDAR_L')
CREATE INDEX IDX_ER_TRIP_VEHICLE_STANDAR_L ON T_ER_TRIP_VEH_STAND_L (FID);

EXEC P_ALTERPK 'PK_T_ER_VEH_TRIPTYPE', 'T_ER_VEH_TRIPTYPE', 'FPKID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_VEH_TRIPTYPE')
CREATE INDEX IDX_ER_VEH_TRIPTYPE ON T_ER_VEH_TRIPTYPE (FID);

EXEC P_ALTERPK 'PK_T_ER_VEH_REIMBURSELEVEL', 'T_ER_VEH_REIMBURSELEVEL', 'FPKID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_VEH_REIMBURSELEVEL')
CREATE INDEX IDX_ER_VEH_REIMBURSELEVEL ON T_ER_VEH_REIMBURSELEVEL (FID);

EXEC P_ALTERPK 'PK_T_ER_VEH_SEAT_ENTRY', 'T_ER_VEH_SEAT_ENTRY', 'FENTRYID', '1';

EXEC P_ALTERPK 'PK_T_ER_VEH_SEAT', 'T_ER_VEH_SEAT', 'FPKID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_VEH_SEA')
CREATE INDEX IDX_ER_VEH_SEA ON T_ER_VEH_SEAT (FID);
/**/


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_VEH_INCLUDEPERSON')
CREATE TABLE T_ER_VEH_INCLUDEPERSON(
    FID         BIGINT DEFAULT 0 NOT NULL,
    FPKID       BIGINT DEFAULT 0 NOT NULL,
    FBASEDATAID BIGINT DEFAULT 0 NOT NULL
);
EXEC P_ALTERPK 'PK_T_ER_VEH_INCLUDEPERSON', 'T_ER_VEH_INCLUDEPERSON', 'FPKID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_VEHINCLUDEPERSON')
CREATE INDEX IDX_ER_VEHINCLUDEPERSON ON T_ER_VEH_INCLUDEPERSON (FID);