Thursday, July 21, 2022

How to create a login on Azure SQL Server DB

You probably realized that you cannot use the traditional approach of creating logins on Azure hosted SQL Server by right-clicking on "Logins" on SSMS.

.

You will have to run the create login scripts manually.  Here is how you can do that.

 

use master

create login <username without quotes> with password = <password enclosed in single quotes>

 

E.g.

use master

create login myappuser with password = 'StranGeBeast123$'

 

If you then need to grant this user access to a specific database, then you have to create a user under that database and link it to this login. Here is how you do that

 

use <your app db>

create user <user without quotes> for login <login without quotes>

 

E.g.

use myWebAppDB

create user myappuser  for login myappuser

 

Then grant any appropriate roles. In this example below, I have granted db_owner role.

 

ALTER ROLE [db_owner] ADD MEMBER myappuser