I can tell if a SQL Server TDE Master Key exists with this T-SQL query:
if not exists (SELECT name FROM sys.symmetric_keys WHERE symmetric_key_id = 101) begin
-- Master Key does not exist. Create one here.
end;
Is there a query to determine whether a database key exists for [mydb]? For example:
use [mydb];
if .... begin
-- database encryption key does not exist. Create one here
end;