How to create the Login and user in the Azure SQL Database/SQL Managed instance

—Step1–Create the Login and user account in the Master database as follow–

CREATE LOGIN TEST01 WITH PASSWORD=’cfdfv@123_^92648451′

CREATE USER TEST01 FROM LOGIN TEST01

–step2–create user for the respective login in the user database—

CREATE USER TEST01 FROM LOGIN TEST01

–Step3–add the user to required role for eg:datareader–

EXEC sp_addrolemember ‘db_datareader’, ‘TEST01’;

https://docs.microsoft.com/en-us/sql/t-sql/statements/create-login-transact-sql?view=sql-server-ver15

If the users required  to create the new tables in the database so you  need to create the customized role as follow.

Example:

CREATE ROLE ModifyTable;

GRANT CREATE TABLE TO ModifyTable;

GRANT ALTER ON SCHEMA::dbo TO ModifyTable;

EXEC sp_addrolemember ‘ModifyTable’, ‘yourlogin’;

https://docs.microsoft.com/en-us/sql/relational-databases/security/authentication-access/database-level-roles?view=sql-server-ver15

Adding Users to Your SQL Azure Database

Published by Santhosh Reddy

I am working as a SQL Server DBA.

Leave a comment