alter table

Use alter table to encrypt or decrypt existing data or to add an encrypted column to a table.

Syntax

Encrypt a column:

alter table tablename add column_name 
            encrypt [with [database.[owner].]keyname

Decrypt an existing column:

[decrypt [with [database.[owner].]keyname]]

keyname – identifies a key created using create encryption key. The creator of the table must have select permission on keyname. If keyname is not supplied, Adaptive Server looks for a default key created using create encryption key or alter encryption key as default.

Example

Example 2

Create an encryption key and encrypt ssn column in existing “employee” table.

alter table employee modify ssn
         encrypt with ssn_key
grant decrypt on employee(ssn) to hr_manager_role,
         hr_director_role

Use alter table to change an encryption key. When the encrypt qualifier is used on a column that is already encrypted, Adaptive Server decrypts the column and re-encrypts it with the new key. This operation may take a significant amount of time if the table contains a large number of rows.