TSQL: Create SQL Logins using certificates and asymmetric keys 70-462

Here’s some TSQL for creating sql logins using certificates and asymmetric keys. Explanatory comments are included.

CREATE CERTIFICATE myCert 
ENCRYPTION BY PASSWORD = 'Secret2014'
WITH SUBJECT = 'My certificate for sql logins';

USE [master]
GO

-- create sql user with the cert
CREATE LOGIN [sql_user_a] FROM CERTIFICATE [myCert];
GO

-- create key
CREATE ASYMMETRIC KEY myKey
WITH ALGORITHM = RSA_2048 
ENCRYPTION BY PASSWORD = 'Secret2014'; 
GO

-- sql user with key
CREATE LOGIN [sql_user_b] FROM ASYMMETRIC KEY [myKey];
GO

Leave a Reply