Create New Database Level User

Create a database-level user in SQL Server/Azure SQL.

commit 381ae9d · authored · 2 min read

Connect to your SQL-Server using privileged account credentials (eg. sa) in your favorite IDE. I still use SSMS together with Azure Data Studio.

Set the query target database, In most IDE, right click on the DB, then new query.

CREATE USER [username]
WITH PASSWORD = 'password'
-- add user to role(s) in db
ALTER ROLE [db_datareader] ADD MEMBER [username];
ALTER ROLE [db_datawriter] ADD MEMBER [username];
ALTER ROLE [db_ddladmin] ADD MEMBER [username];
GRANT EXECUTE TO [username]

Execute the above statement after replacing the username and password according to your choice. You can also manage the roles as per your needs.

Some of the Fixed-database roles are,

Fixed-Database role nameDescription
db_ownerMembers of the db_owner fixed database role can perform all configuration and maintenance activities on the database, and can also drop the database in SQL Server. (In SQL Database and Azure Synapse, some maintenance activities require server-level permissions and cannot be performed by db_owners.)
db_ddladminMembers of the db_ddladmin fixed database role can run any Data Definition Language (DDL) command in a database.
db_datawriterMembers of the db_datawriter fixed database role can add, delete, or change data in all user tables.
db_datareaderMembers of the db_datareader fixed database role can read all data from all user tables and views. User objects can exist in any schema except sys and INFORMATION_SCHEMA.

Note: In order to connect to the DB using the new credentials, you need to specify the database name in the advanced options from your IDE since the above credentials don’t have the privilege to list the DB’s in the server.

Additional Resources

local graph · open full graph

"Create New Database Level User" is connected to the topics SQL Server, Security and related to 7 other entries. Style Guide - SQL Server Auditing Column Names Style Guide - SQL Server Au… SQL Server - Delete Duplicate Rows SQL Server - Delete Duplica… Dapper - Execute Multiple Stored Procedures Dapper - Execute Multiple S… Create SQL Server Database From a Script in Docker-Compose Create SQL Server Database … Microsoft SQL Server Guy Trying Oracle Database Microsoft SQL Server Guy Tr… Docker - SQL Error on ASP.NET Core Alpine Docker - SQL Error on ASP.N… UTC to UAE Time (Arabian Standard Time) UTC to UAE Time (Arabian St… SQL Server #sql-server Security #security Create New Database Level User

comments

loading discussion…