Creating a master key in SQL Server

4.1k views Asked by At

I'm trying to implement an encrypted column as in this following MSDN example. I understand most of the code except for the very first line:

--If there is no master key, create one now. 
IF NOT EXISTS (SELECT * FROM sys.symmetric_keys WHERE symmetric_key_id = 101)

When I run that on the AdventureWorks database on my local machine, the key already exists, which is fine; I got the example to run fine and encrypt/decrypt properly on my machine. However in that code there is no mention of a symmetric_key_id of 101 any at any point.

Is 101 some kind of reserved ID for symmetric keys?

1

There are 1 answers

0
aF. On BEST ANSWER

As seen HERE, the symmetric_key_id 101 is the id for the Database Master Key.

The number of database master keys is limited only by the number of databases you have - you can have one master key per database and its id is 101.