IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PERM_ENCRYPTIONSCHEME') 
 CREATE TABLE T_PERM_ENCRYPTIONSCHEME (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(80) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
FALGORITHM VARCHAR(50) DEFAULT ' ' NOT NULL,
FLENGTH VARCHAR(10) DEFAULT ' ' NOT NULL,
FSCHEMEKEY NVARCHAR(512) DEFAULT ' ' NOT NULL
);

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

EXEC P_ALTERPK 'PK_T_PERM_ENCRYPTIONSCHEME', 'T_PERM_ENCRYPTIONSCHEME', 'FID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_PERM_ENCRYPTIONSCHEME_NUM') CREATE INDEX IDX_PERM_ENCRYPTIONSCHEME_NUM ON T_PERM_ENCRYPTIONSCHEME ( FNUMBER );

EXEC P_ALTERPK 'PK_T_PERM_ENCRYPTIONSCHEME_L', 'T_PERM_ENCRYPTIONSCHEME_L', 'FPKID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_PERM_ENCRYPTIONSCHEME_L_ID') CREATE INDEX IDX_PERM_ENCRYPTIONSCHEME_L_ID ON T_PERM_ENCRYPTIONSCHEME_L ( FID ,FLOCALEID );
