A single excessive permission can expose sensitive data, compromise critical databases, or put an entire SQL Server environment at risk. Yet, many security issues begin with something as simple as granting users more access than they actually need. The Principle of Least Privilege helps DBAs minimize these risks by ensuring users have only the permissions required to perform their tasks. In this article, we will explore SQL Server permissions and practical ways to implement this essential security principle.

Figure-1: Implementing the Principle of Least Privilege
Some Key Concepts
Principle of Least Privilege
Principle of Least Privilege (PoLP) is a security practice that ensures every user, application, or service account is granted only the minimum permissions necessary to perform its assigned tasks. For example, if an application only needs to retrieve customer information from customer table, it should be granted SELECT permission on the customer table rather than db_owner or db_datareader access to the entire database.
Why is it important?
- Reduces the risk of unauthorized data access.
- Limits the damage caused by compromised accounts.
- Prevents accidental data modification or deletion.
- Strengthens overall database security.
Remember: Do not grant users access because they might need it someday. Grant only what they need today.
Access Control Model
- Securables are database objects (tables, views, stored procedures) that require protection.
- Principals are entities (users, logins, applications) who request to access securables.
- Permissions are permitted actions (GRANT, DENY, REVOKE) on securables.
Authentication
SQL Server validates identities before granting access to the engine.
- Windows & Microsoft Entra Authentication (Recommended) - users use their windows account/Active Directory/Entra ID to login without storing password hashes inside SQL Server.
- SQL Server Authentication - users use SQL Login (username & password) for login.
- Contained Database Users - users can directly login at the database level rather than the instance level. This make databases portable across servers without orphaned logins.
Logins and Users
Though they tend to be same, but there are differences between logins and users.
- Login - ensures access to instance level.
- User - associated with a login and allow access to the designated database.
Role-Based Access Control (RBAC)
You can assign SQL Server groups privileges to roles. Some built-in roles are:
- Server level roles
- sysadmin has full control over the server.
- serveradmin can change server-wide settings.
- securityadmin can manage logins and permissions.
- dbcreator has privilege to create/alter/drop databases.
- public by default every logins are in this group.
- Database level roles
- db_owner has privilege to control the full database.
- db_datareader has permission to read all data.
- db_datawriter enjoys rights to modify all data.
- db_ddladmin can modify schema (tables, views, stored procedure).
- db_securityadmin manages database roles and permissions.
Permissions Manipulation
Apart from standard role based access, you can also customize access to securables by using:
- GRANT gives permission to perform an action.
- DENY restricts to perform an action.
- REVOKE removes the last GRANT or DENY permission.
Implementing Principle of Least Privilege (PoLP)
Finding out Existing Users and Their Privileges
Find out the existing users and their privileges of your database. Sometimes, we may reveal some obsolete users (who were created once for specific usages and currently no more using) or users having excessive permissions. Query Snippet-1 will reveal all the users with their roles (Figure-2).
SELECT
DB_NAME() AS DatabaseName,
dp.name AS DatabaseUser,
dp.type_desc AS UserType,
rp.name AS DatabaseRole,
sp.name AS LoginName
FROM sys.database_role_members AS drm
INNER JOIN sys.database_principals AS rp
ON drm.role_principal_id = rp.principal_id
INNER JOIN sys.database_principals AS dp
ON drm.member_principal_id = dp.principal_id
LEFT JOIN sys.server_principals AS sp
ON dp.sid = sp.sid
ORDER BY
rp.name,
dp.name;
-- Query Snippet-1

Figure-2: Users with their roles
Remove Additional Privileges
Scrutinize each user's role carefully. Match with their exact access requirements and allow accordingly. For example, let's say user mehedi2 only needs to select schemas of Human Resource department. However, in current configuration he has full read/write access. Query Snippet-2 will give him access only to Human Resource schemas.
USE [AdventureWorks2022];
GO
-- Remove excessive reader roles
ALTER ROLE db_datareader DROP MEMBER [mehedi2];
GO
-- Remove excessive modification roles
ALTER ROLE db_datawriter DROP MEMBER [mehedi2];
GO
-- Allow only read permission to [HumanResources] schemas
GRANT SELECT ON SCHEMA::[HumanResources] TO [mehedi2];
GO
-- Query Snippet-2
Even you can permit table level or more granular level like column wise access using Query Snippet-3.
-- Allow only read permission to [Person].[Person] table
GRANT SELECT ON OBJECT::[Person].[Person] TO [mehedi2];
GO
-- Revoke read permission from [Person].[Person] table
REVOKE SELECT ON OBJECT::[Person].[Person] TO [mehedi2];
GO
-- Grant read access only to non-sensitive columns
GRANT SELECT ON [Person].[Person] ([FirstName], [MiddleName], [LastName]) TO [mehedi2];
GO
-- Or explicitly block a specific column (overrides table-level grants)
DENY SELECT ON [Person].[Person] ([FirstName]) TO [mehedi2];
GO
-- Query Snippet-3
Table-level and Column-level Security Within Stored Procedure
If the stored procedure and the underlying table share the same owner (usually dbo), SQL Server ownership chaining bypasses table-level and column-level permissions checking. Which includes DENY or GRANT column-level rules on the table. Even ownership chaining breaks when a stored procedure executes dynamic SQL (EXEC or sp_executesql). In these cases, you can enforce security by:
- Using
EXECUTE AS CALLER in stored procedure with dynamic SQL.
- Assigning the stored procedure and the table to different owners (e.g., place the stored procedure in a separate schema owned by a different user/role).
- Creating distinct stored procedures for different security levels. For example:
- dbo.GetPersonPublic. Selects only non-sensitive columns. GRANT EXECUTE to general users.
- dbo.GetPersonFull. Selects all columns including sensitive ones. GRANT EXECUTE only to privileged roles.
Best Practices
- Use Windows Authentication.
- Periodically review logins and permissions and apply PoLP on them.
- Establish a process for on boarding a new user with minimum access.
- Disable or rename sa account. It has full and unrestricted access to everything.
Final Words
Implementing the Principle of Least Privilege is essential to protecting SQL Server databases from unauthorized access and unnecessary risks. By granting only the permissions users need and reviewing access regularly, DBAs can strengthen security and maintain better control over their databases. Remember, the less access you grant, the less risk you expose.
References
Going Further
If SQL Server is your thing and you enjoy learning real-world tips, tricks, and performance hacks—you are going to love my training sessions too!
Need results fast? I am also available for 1-on-1 consultancy to help you troubleshoot and fix your database performance issues.
Let’s make your SQL Server to take your business Challenge!
For any queries, mail to mamehedi.hasan[at]gmail.com.