IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PERM_DATARULE') 
 CREATE TABLE T_PERM_DATARULE (
FID BIGINT DEFAULT 0 NOT NULL,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(60) DEFAULT ' ' NOT NULL,
FBIZAPPID VARCHAR(36) DEFAULT ' ' NOT NULL,
FENTITYNUM VARCHAR(36) DEFAULT ' ' NOT NULL,
FRULE NCLOB,
FISDETAIL CHAR(1) DEFAULT '1' NOT NULL,
FCREATETIME DATETIME,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFYTIME DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FSTATUS NVARCHAR(30) DEFAULT ' ' NOT NULL,
FENABLE CHAR(1) DEFAULT '1' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PERM_DATARULE_ENTRY') 
 CREATE TABLE T_PERM_DATARULE_ENTRY (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FPERMITEMID VARCHAR(18) DEFAULT ' ' NOT NULL,
FOPKEY VARCHAR(30) DEFAULT ' ' NOT NULL,
FOPTYPE VARCHAR(30) DEFAULT ' ' NOT NULL,
FDATARULEID BIGINT DEFAULT 0 NOT NULL
);


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


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


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PERM_ROLEDATARULES') 
 CREATE TABLE T_PERM_ROLEDATARULES (
FID BIGINT DEFAULT 0 NOT NULL,
FDATARULESID BIGINT DEFAULT 0 NOT NULL,
FROLEID VARCHAR(18) DEFAULT ' ' NOT NULL,
FCREATETIME DATETIME,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFYTIME DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PERM_USERDATAPERM' AND KSQL_COL_NAME ='FISUPDATE') 
 ALTER TABLE T_PERM_USERDATAPERM ADD (FISUPDATE CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PERM_USERDATAPERM' AND KSQL_COL_NAME ='FUPDATETIME') 
 ALTER TABLE T_PERM_USERDATAPERM ADD (FUPDATETIME DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PERM_USERDATAPERM' AND KSQL_COL_NAME ='FUPDATORID') 
 ALTER TABLE T_PERM_USERDATAPERM ADD (FUPDATORID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PERM_DATARULE_PROP') 
 CREATE TABLE T_PERM_DATARULE_PROP (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FPROPKEY VARCHAR(60) DEFAULT ' ' NOT NULL,
FDATARULEID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PERM_DATARULES') 
 CREATE TABLE T_PERM_DATARULES (
FID BIGINT DEFAULT 0 NOT NULL,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(30) DEFAULT ' ' NOT NULL,
FSTATUS NVARCHAR(30) DEFAULT ' ' NOT NULL,
FENABLE CHAR(1) DEFAULT '1' NOT NULL,
FCREATETIME DATETIME,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFYTIME DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PERM_DATARULES_ENTRY') 
 CREATE TABLE T_PERM_DATARULES_ENTRY (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FBIZAPPID VARCHAR(36) DEFAULT ' ' NOT NULL,
FENTITYNUM VARCHAR(36) DEFAULT ' ' NOT NULL,
FDATARULEID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PERM_USERDATARULES') 
 CREATE TABLE T_PERM_USERDATARULES (
FID BIGINT DEFAULT 0 NOT NULL,
FUSERID BIGINT DEFAULT 0 NOT NULL,
FDATARULESID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFYTIME DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PERM_ROLEDATAPERM' AND KSQL_COL_NAME ='FISUPDATE') 
 ALTER TABLE T_PERM_ROLEDATAPERM ADD (FISUPDATE CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PERM_ROLEDATAPERM' AND KSQL_COL_NAME ='FUPDATETIME') 
 ALTER TABLE T_PERM_ROLEDATAPERM ADD (FUPDATETIME DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PERM_ROLEDATAPERM' AND KSQL_COL_NAME ='FUPDATORID') 
 ALTER TABLE T_PERM_ROLEDATAPERM ADD (FUPDATORID BIGINT DEFAULT 0 NOT NULL );
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PERM_DATARULE_PROP' AND KSQL_COL_NAME ='FPROPENTNUM') 
 ALTER TABLE T_PERM_DATARULE_PROP ADD (FPROPENTNUM VARCHAR(36) DEFAULT ' ' ); 
 
 
 