/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\BOS_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PERM_PRIVACYSTMT')
 CREATE TABLE T_PERM_PRIVACYSTMT (
FID BIGINT DEFAULT 0 NOT NULL,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(80) DEFAULT ' ' NOT NULL,
FVERSION NVARCHAR(80) DEFAULT ' ' NOT NULL,
FENABLE CHAR(1) DEFAULT '1' NOT NULL,
FSTATUS NVARCHAR(50) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FMODIFYTIME DATETIME,
FDISABLERID BIGINT DEFAULT 0 NOT NULL,
FDISABLEDATE DATETIME
);

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

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PERM_USERPRIVACYSTMT')
 CREATE TABLE T_PERM_USERPRIVACYSTMT (
FID BIGINT DEFAULT 0 NOT NULL,
FUSERID BIGINT DEFAULT 0 NOT NULL,
FPRIVACYSTMTID BIGINT DEFAULT 0 NOT NULL,
FISAGREE CHAR(1) DEFAULT '0' NOT NULL,
FMODIFYTIME DATETIME
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PERM_USERPRIVACYSTMT_H')
 CREATE TABLE T_PERM_USERPRIVACYSTMT_H (
FID BIGINT DEFAULT 0 NOT NULL,
FUSERID BIGINT DEFAULT 0 NOT NULL,
FPRIVACYSTMTID BIGINT DEFAULT 0 NOT NULL,
FISAGREE CHAR(1) DEFAULT '0' NOT NULL,
FMODIFYTIME DATETIME
);

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

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PERM_PRIVACYSTMT' AND KSQL_COL_NAME ='FFORMID') 
 ALTER TABLE T_PERM_PRIVACYSTMT ADD (FFORMID VARCHAR(60) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PERM_PRIVACYSTMT' AND KSQL_COL_NAME ='FLOCALEID') 
 ALTER TABLE T_PERM_PRIVACYSTMT ADD (FLOCALEID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PERM_PRIVACYSTMT' AND KSQL_COL_NAME ='FCONTENT') 
 ALTER TABLE T_PERM_PRIVACYSTMT ADD (FCONTENT NCLOB DEFAULT ' ' );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PERM_PRIVACYSTMT' AND KSQL_COL_NAME ='FCONTENT_TAG')
 ALTER TABLE T_PERM_PRIVACYSTMT ADD (FCONTENT_TAG NCLOB DEFAULT ' ' );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PERM_PRIVACYSTMTTPL') 
 CREATE TABLE T_PERM_PRIVACYSTMTTPL (
FID BIGINT DEFAULT 0 NOT NULL,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(80) DEFAULT ' ' NOT NULL,
FVERSION NVARCHAR(80) DEFAULT ' ' NOT NULL,
FFORMID VARCHAR(60) DEFAULT ' ' NOT NULL,
FLOCALEID BIGINT DEFAULT 0 NOT NULL,
FCONTENT NCLOB DEFAULT ' ',
FENABLE CHAR(1) DEFAULT '1' NOT NULL,
FSTATUS NVARCHAR(50) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FMODIFYTIME DATETIME,
FDISABLERID BIGINT DEFAULT 0 NOT NULL,
FDISABLEDATE DATETIME
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PERM_PRIVACYSTMTTPL' AND KSQL_COL_NAME ='FCONTENT_TAG')
 ALTER TABLE T_PERM_PRIVACYSTMTTPL ADD (FCONTENT_TAG NCLOB DEFAULT ' ' );

 EXEC P_ALTERPK 'PK_T_PERM_PRIVACYSTMT', 'T_PERM_PRIVACYSTMT', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_T_PERM_PRIVACYSTMT_NUMBER') CREATE INDEX IDX_T_PERM_PRIVACYSTMT_NUMBER ON T_PERM_PRIVACYSTMT ( FNUMBER );


 EXEC P_ALTERPK 'PK_T_PERM_USERPRIVACYSTMT', 'T_PERM_USERPRIVACYSTMT', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'UX_USERPRIVACYSTMT_USER') CREATE UNIQUE INDEX UX_USERPRIVACYSTMT_USER ON T_PERM_USERPRIVACYSTMT ( FUSERID ,FPRIVACYSTMTID );


 EXEC P_ALTERPK 'PK_T_PERM_USERPRIVACYSTMT_H', 'T_PERM_USERPRIVACYSTMT_H', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_USERPRIVACYSTMT_H_USER') CREATE INDEX IDX_USERPRIVACYSTMT_H_USER ON T_PERM_USERPRIVACYSTMT_H ( FUSERID );

 EXEC P_ALTERPK 'PK_T_PERM_PRIVACYSTMT_L', 'T_PERM_PRIVACYSTMT_L', 'FPKID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_T_PERM_PRIVACYSTMT_L_FID') CREATE INDEX IDX_T_PERM_PRIVACYSTMT_L_FID ON T_PERM_PRIVACYSTMT_L ( FID ,FLOCALEID );

 EXEC P_ALTERPK 'PK_T_PERM_PRIVACYSTMTTPL_L', 'T_PERM_PRIVACYSTMTTPL_L', 'FPKID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_T_PERM_PRIVACYSTMTTPL_L') CREATE INDEX IDX_T_PERM_PRIVACYSTMTTPL_L ON T_PERM_PRIVACYSTMTTPL_L ( FID ,FLOCALEID );

 EXEC P_ALTERPK 'PK_T_PERM_PRIVACYSTMTTPL', 'T_PERM_PRIVACYSTMTTPL', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_T_PERM_PRIVACYSTMTTPL_NUM') CREATE INDEX IDX_T_PERM_PRIVACYSTMTTPL_NUM ON T_PERM_PRIVACYSTMTTPL ( FNUMBER );

 EXEC p_AlterColumn 'T_PERM_PRIVACYSTMT', 'FFORMID', 'VARCHAR(100)', 'NOT NULL', '0100', ''' ''';
/**End E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\BOS_table.sql **/