Paramclasses Academy - Blog

Tutorials Details

←
Post 33 of 40
→

SQL Server Login and User Management Explained: Windows Authentication, SQL Authentication, Roles and Permissions

SQL Server Login and User Management Explained: Windows Authentication, SQL Authentication, Roles and Permissions

November 18, 2026

???? SQL Server Login and User Management: Authentication and Permissions

Welcome to Param Classes! In this practical SQL Server tutorial, we will learn how to create and manage SQL Server logins and database users, understand Windows Authentication and SQL Server Authentication, assign server and database roles, and control access using permissions.

Database security is an essential part of database administration. A database may contain customer information, employee records, financial transactions, business reports, and other confidential data. Giving every user full access can create serious security risks.

SQL Server provides a security system that helps administrators control who can connect to the server and what actions they can perform inside a database.

In this tutorial, we will understand these concepts step by step with practical T-SQL examples.


???? 1. What Is SQL Server Login and User Management?

SQL Server Login and User Management is the process of creating identities, authenticating connections, and assigning permissions to users.

There are two important concepts:

  • Login: A security principal used to connect to the SQL Server Database Engine.

  • Database User: A security principal inside a particular database that receives database-level permissions.

A login and a database user are related, but they are not the same thing.

For example, an employee may have a login that allows connection to a SQL Server instance. To access a particular database, that login normally needs a mapped database user and suitable permissions.

Main benefits of user management:

  • ???? Protect confidential database information.

  • ???? Control access for different employees and applications.

  • ????️ Prevent unauthorized database operations.

  • ???? Assign permissions according to job responsibilities.

  • ⚙️ Maintain a secure and manageable database environment.


???? 2. Understand SQL Server Authentication

SQL Server supports different authentication methods.

1. Windows Authentication

Windows Authentication uses a Windows account or Windows group to authenticate a connection.

Example: An employee signs in to a company computer using their Windows domain account and connects to SQL Server using Windows credentials.

Benefits:

  • Uses existing Windows identity management.

  • Supports Windows groups.

  • Avoids storing a separate SQL Server password for each Windows account.

  • Can integrate with organizational security policies.

2. SQL Server Authentication

SQL Server Authentication uses a SQL Server login name and password.

Example login:

CREATE LOGIN param_user
WITH PASSWORD = 'Use_A_Strong_Unique_Password_123!';

This creates a SQL Server login named param_user.

Important: SQL Server Authentication requires the server to be configured for Mixed Mode Authentication. Use a strong, unique password and do not place real production passwords in source code or public tutorials.

Windows Authentication vs SQL Server Authentication

Feature Windows Authentication SQL Server Authentication
Identity source Windows account or group SQL Server login
Password management Managed by Windows Managed by SQL Server
Windows integration Yes No
Mixed Mode required No Yes
Common use Organization environments Applications or environments requiring SQL logins

????️ 3. Understand the Difference Between Login and Database User

A SQL Server login is created at the server level, while a database user belongs to a specific database.

Example:

  • Login: param_user

  • Database: TrainingDB

  • Database User: param_user

The login provides the identity used to connect to the instance. The mapped database user receives permissions inside TrainingDB.

A single login can be mapped to users in multiple databases. A login can have only one corresponding mapped user in a particular database.


????️ 4. Create a Sample Database

Let's create a database for practical security examples.

CREATE DATABASE TrainingDB;
GO

USE TrainingDB;
GO

CREATE TABLE Students
(
    StudentID INT PRIMARY KEY,
    StudentName VARCHAR(100),
    Course VARCHAR(50),
    Fees DECIMAL(10,2)
);
GO

INSERT INTO Students
(StudentID, StudentName, Course, Fees)
VALUES
(1, 'Amit Sharma', 'SQL Server', 12000),
(2, 'Priya Verma', 'Python', 15000),
(3, 'Rahul Patel', 'Web Development', 10000);
GO

Now we will create a login and map it to this database.


???? 5. Create a SQL Server Login

Use the following command:

USE master;
GO

CREATE LOGIN param_user
WITH PASSWORD = 'Use_A_Strong_Unique_Password_123!';
GO

The login is now created at the SQL Server instance level.

To view SQL Server logins, you can use:

SELECT
    name,
    type_desc,
    is_disabled
FROM sys.server_principals
WHERE type IN ('S', 'U', 'G');

This query displays SQL logins and Windows-based principals.


???? 6. Create a Database User and Map the Login

Creating a login alone does not automatically provide access to every user database.

First select the target database:

USE TrainingDB;
GO

CREATE USER param_user
FOR LOGIN param_user;
GO

The database user is now mapped to the server login.

You can inspect database users using:

SELECT
    name,
    type_desc,
    authentication_type_desc
FROM sys.database_principals
WHERE principal_id > 4;

Remember: A login and user are separate security objects with different scopes.


????️ 7. Understand Server-Level Roles

Server-level roles manage permissions across the SQL Server instance.

Some commonly used fixed server roles include:

Server Role Purpose
sysadmin Full control over the SQL Server instance
serveradmin Manages server-wide configuration and shutdown
securityadmin Manages logins and server-level security
processadmin Manages SQL Server processes
dbcreator Creates, alters, drops, and restores databases
bulkadmin Allows supported bulk import operations
setupadmin Manages linked servers through supported operations

Example: Add a login to a server role:

ALTER SERVER ROLE dbcreator
ADD MEMBER param_user;

This grants broad database-creation capabilities. Assign such roles only when the job genuinely requires them.

Security Tip: Avoid adding ordinary application users to sysadmin. It provides extensive control over the entire SQL Server instance.


???? 8. Understand Database-Level Roles

Database-level roles manage permissions inside a particular database.

Common fixed database roles include:

Database Role Purpose
db_owner Full control over the database
db_datareader Reads data from user tables and views
db_datawriter Inserts, updates, and deletes data in user tables
db_ddladmin Can run supported DDL operations
db_securityadmin Manages database permissions and role membership
public Default role for every database user

Example: Add a user to the database reader role:

USE TrainingDB;
GO

ALTER ROLE db_datareader
ADD MEMBER param_user;

Now the user receives the permissions associated with db_datareader in TrainingDB.

For production systems, consider creating custom roles with only the permissions required for each job.


???? 9. Grant Permissions to a Database User

The GRANT statement gives a principal permission to perform an action.

Example: Allow the user to read the Students table.

GRANT SELECT
ON OBJECT::dbo.Students
TO param_user;

Allow the user to insert records:

GRANT INSERT
ON OBJECT::dbo.Students
TO param_user;

Allow the user to update records:

GRANT UPDATE
ON OBJECT::dbo.Students
TO param_user;

These permissions can be assigned individually rather than giving the user a broad database role.


???? 10. Understand DENY and REVOKE

SQL Server provides three important permission statements.

GRANT

Allows a specified action.

GRANT SELECT
ON OBJECT::dbo.Students
TO param_user;

DENY

Explicitly denies a specified permission.

DENY DELETE
ON OBJECT::dbo.Students
TO param_user;

REVOKE

Removes an explicit GRANT or DENY permission.

REVOKE SELECT
ON OBJECT::dbo.Students
FROM param_user;

Important Difference:

Command Meaning
GRANT Gives permission
DENY Explicitly denies permission
REVOKE Removes an explicit permission assignment

A DENY normally takes precedence over a GRANT, except in certain ownership and privileged-role situations. Use REVOKE when you want to remove an explicit permission assignment rather than create a denial.


???? 11. Create a Custom Database Role

For better security management, create custom roles based on job responsibilities.

Example:

USE TrainingDB;
GO

CREATE ROLE StudentViewer;
GO

GRANT SELECT
ON OBJECT::dbo.Students
TO StudentViewer;
GO

ALTER ROLE StudentViewer
ADD MEMBER param_user;
GO

Now param_user receives the SELECT permission through the StudentViewer role.

Why use custom roles?

  • Easier permission management.

  • Better organization of user access.

  • Less repetitive permission assignment.

  • More control over job-based database access.


????️ 12. Create Login and User Through SSMS

You can also manage logins using SQL Server Management Studio.

Follow these steps:

  1. Open SQL Server Management Studio.

  2. Connect to your SQL Server instance.

  3. Expand the Security folder.

  4. Right-click Logins.

  5. Select New Login.

  6. Enter a login name.

  7. Select Windows Authentication or SQL Server Authentication.

  8. For SQL Authentication, enter a strong password.

  9. Open User Mapping.

  10. Select the required database.

  11. Assign only the required database roles.

  12. Click OK.

You can also create database users by expanding the target database, opening Security, and selecting Users.


???? 13. Check Login Status and Disable a Login

To check whether a login is disabled:

SELECT
    name,
    is_disabled
FROM sys.sql_logins;

To disable a SQL Server login:

ALTER LOGIN param_user DISABLE;

To enable it again:

ALTER LOGIN param_user ENABLE;

Disabling a login prevents new connections using that login. Review active sessions and application dependencies before making changes.


???? 14. SQL Server User Management Best Practices

Follow these security practices:

  1. Apply the principle of least privilege.

  2. Avoid granting sysadmin access to ordinary users.

  3. Prefer Windows Authentication when it fits the organization's identity-management environment.

  4. Use strong, unique passwords for SQL Server logins.

  5. Assign permissions through suitable custom roles.

  6. Review login and user access regularly.

  7. Remove or disable accounts that are no longer required.

  8. Avoid sharing administrator credentials.

  9. Protect application connection strings and secrets.

  10. Monitor important permission and login changes.


❓ 15. Frequently Asked Questions (FAQs)

Q1. What is a SQL Server login?

A login is a server-level security principal used to authenticate a connection to the SQL Server Database Engine.

Q2. What is a database user?

A database user is a security principal inside a particular database that receives database-level permissions.

Q3. What is the difference between Windows Authentication and SQL Server Authentication?

Windows Authentication uses a Windows identity, while SQL Server Authentication uses a SQL Server login name and password.

Q4. What is the purpose of the sysadmin role?

The sysadmin fixed server role provides extensive administrative control over the SQL Server instance.

Q5. What is the difference between GRANT, DENY, and REVOKE?

GRANT allows a permission, DENY explicitly blocks it, and REVOKE removes an explicit permission assignment.

Q6. Why should we use custom database roles?

Custom roles make it easier to assign permissions according to job responsibilities while following the principle of least privilege.


???? 16. Conclusion

SQL Server Login and User Management is a fundamental part of database security. Understanding authentication, logins, database users, server roles, database roles, and permissions helps administrators protect databases and control access effectively.

In this tutorial, we learned how to create SQL Server logins, map database users, assign roles, use GRANT, DENY, and REVOKE, create custom roles, and manage login status using practical T-SQL examples.

At Param Classes, we focus on practical SQL Server training that helps students understand database security and develop real-world database administration skills.

???? Learn SQL Server Security. Manage Users. Protect Your Data with Param Classes!

←
Post 33 of 40
→