Search code examples
sql-serverazuresecuritypermissionsuser-accounts

Syntax question for assigning an existing user to a login account in Azure


If I was creating a brand new login credentials in a brand new Azure database, I would do the following:

create login kmistry with Password = 'xxxxxxxxxxxx'
Create User AuditUser from login kmistry

Now that I already have AuditUser defined with all necessary permissions, I want to create another similar login.

create login jperez with Password = 'xxxxxxxxxxxx'

Now, I don't want to create AuditUser. I just want to say jperez is also an AuditUser.

How do I do that assignment?


Solution

  • Like @Larnu said, One login for one user. We can not map multiple SQL users to one login.

    LOGIN is SQL Server level and User is database level. That's why CREATE LOGIN must be in master db, and CREATE USER only need to be in the current database.

    LOGIN is used to login the SQL Server, you need to grant the USER different roles to determine which database the user has the permission to access or alter. Ref: ALTER ROLE.

    In usually, we often create the login and user with the same name.

    Hope this helps.