How do I create a user on an Azure SQL database?

  • Page Owner: Not Set
  • Last Reviewed: 2020-08-11

I don't want to use the primary user, how do I create a database-specific user with full access?


Answer

Create the database and open a connection to the server in SQL Server Management Studio using the primary / root account.

Select the master database and run the command:

CREATE LOGIN websiteuser WITH password='RANDOMPASSWORDHERE';

Obviously, replace websiteuser and RANDOMPASSWORDHERE. Probably put these in 1Password.

Now select the database you want to tie the user to. NOTE: You can't use USE, because Azure SQL doesn't like it. You have to switch the connection with the dropdown in SSMS, or disconnect and reconnect. Once connected to the correct database, run:

CREATE USER websiteuser FROM LOGIN websiteuser;
EXEC sp_addrolemember 'db_owner', 'websiteuser';

And that should do it.