Columns with decrypt default values

There are no restrictions on how you use columns with the decrypt default attribute in a query. You can use them in a target list expression, where clause, order by, group by, or subquery. Although expressions on the decrypt default constant value may not have a practical use, placing a decrypt default on a column does not impose any syntactic restrictions on use of the column in a Transact-SQL™ statement.

This example uses a select statement on a column with a decrypt default value in the target list:

create table emp_benefits (col1 name char(30),
     salary float encrypt decrypt_default -99.99)
select salary/12 as monthly_salary from emp_benefits
     where name = 'Bill Smith'

When you perform the select statement against this table, but do not have decrypt permission, you see:

monthly_salary
---------------------
8.332500

When Adaptive Server returns a column’s decrypt default value on a select into command, this decrypt default value is inserted into the target table. However, the target column does not inherit the decrypt default property. You must use alter table to specify a decrypt default on the target table.