You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/relational-databases/security/authentication-access/create-a-database-user.md
+11-7Lines changed: 11 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
---
2
-
title: "Create a database user"
2
+
title: "Create a Database User"
3
3
description: Learn how to create the most common types of database users by using SQL Server Management Studio or Transact-SQL.
4
4
author: VanMSFT
5
5
ms.author: vanto
6
6
ms.reviewer: randolphwest
7
-
ms.date: 07/18/2024
7
+
ms.date: 06/30/2025
8
8
ms.service: sql
9
9
ms.subservice: security
10
10
ms.topic: how-to
@@ -38,15 +38,15 @@ You can create a database user by using [!INCLUDE [ssManStudioFull](../../../inc
38
38
39
39
[!INCLUDE [ssManStudio](../../../includes/ssmanstudio-md.md)] presents six options when creating a database user. The following diagram shows the six options in the green box, and indicates what they represent.
40
40
41
-
:::image type="content" source="media/typesofusers.png" alt-text="Diagram that explains the different types of users.":::
41
+
:::image type="content" source="media/create-a-database-user/types-of-users.png" alt-text="Diagram that explains the different types of users.":::
42
42
43
43
### Select the type of user
44
44
45
45
If you're new to [!INCLUDE [ssNoVersion](../../../includes/ssnoversion-md.md)], it can be difficult to determine what type of user you want to create. First ask yourself, does the person or group that needs to access the database have a login?
46
46
47
47
#### Create a user with a login
48
48
49
-
Logins in the `master` database are common for the people who manage the [!INCLUDE [ssNoVersion](../../../includes/ssnoversion-md.md)] and for people who need to access many or all of the database on the instance of [!INCLUDE [ssNoVersion](../../../includes/ssnoversion-md.md)]. For this situation, create a **SQL user with login**. The database user is the identity of the login when it connects to a database. The database user can use the same name as the login, but that isn't required. This article assumes that a login already exists in [!INCLUDE [ssNoVersion](../../../includes/ssnoversion-md.md)]. For information about how to create a login, see [Create a Login](create-a-login.md).
49
+
Logins in the `master` database are common for the people who manage the [!INCLUDE [ssNoVersion](../../../includes/ssnoversion-md.md)] and for people who need to access many or all of the database on the instance of [!INCLUDE [ssNoVersion](../../../includes/ssnoversion-md.md)]. For this situation, create a **SQL user with login**. The database user is the identity of the login when it connects to a database. The database user can use the same name as the login, but that isn't required. This article assumes that a login already exists in [!INCLUDE [ssNoVersion](../../../includes/ssnoversion-md.md)]. For information about how to create a login, see [Create a login](create-a-login.md).
50
50
51
51
#### Create user without a login
52
52
@@ -75,7 +75,9 @@ As a security principal, permissions can be granted to users. The scope of a use
75
75
76
76
Requires `ALTER ANY USER` permission on the database.
77
77
78
-
## <aid="SSMSProcedure"></a> Create a user with SSMS
78
+
<aid="SSMSProcedure"></a>
79
+
80
+
## Create a user with SSMS
79
81
80
82
1. In Object Explorer, expand the **Databases** folder.
81
83
@@ -158,7 +160,9 @@ The **Database User - New** dialog box also offers options on four other pages:
158
160
159
161
Removes the selected extended property.
160
162
161
-
## <aid="TsqlProcedure"></a> Create a user using T-SQL
163
+
<aid="TsqlProcedure"></a>
164
+
165
+
## Create a user using T-SQL
162
166
163
167
1. In **Object Explorer**, connect to an instance of [!INCLUDE [ssDE](../../../includes/ssde-md.md)].
164
168
@@ -183,5 +187,5 @@ For more information, see [CREATE USER](../../../t-sql/statements/create-user-tr
A login is a security principal, or an entity that can be authenticated by a secure system. Users need a login to connect to [!INCLUDE [ssNoVersion](../../../includes/ssnoversion-md.md)]. You can create a login based on a Windows principal (such as a domain user or a Windows domain group) or you can create a login that isn't based on a Windows principal (such as an [!INCLUDE [ssNoVersion](../../../includes/ssnoversion-md.md)] login).
> To use [!INCLUDE [ssNoVersion](../../../includes/ssnoversion-md.md)] Authentication, the [!INCLUDE [ssDE](../../../includes/ssde-md.md)] must use mixed mode authentication. For more information, see [Choose an Authentication Mode](../../../relational-databases/security/choose-an-authentication-mode.md).
43
+
> To use [!INCLUDE [ssNoVersion](../../../includes/ssnoversion-md.md)] Authentication, the [!INCLUDE [ssDE](../../../includes/ssde-md.md)] must use mixed mode authentication. For more information, see [Choose an authentication mode](../choose-an-authentication-mode.md).
42
44
>
43
45
> Azure SQL has introduced [Microsoft Entra server principals (logins)](/azure/azure-sql/database/authentication-azure-ad-logins) to be used to authenticate to Azure SQL Database, Azure SQL Managed Instance, and Azure Synapse Analytics (dedicated SQL pools only).
44
46
>
@@ -47,15 +49,19 @@ A login is a security principal, or an entity that can be authenticated by a sec
47
49
As a security principal, permissions can be granted to logins. The scope of a login is the whole [!INCLUDE [ssDE](../../../includes/ssde-md.md)]. To connect to a specific database on the instance of [!INCLUDE [ssNoVersion](../../../includes/ssnoversion-md.md)], a login must be mapped to a database user. Permissions inside the database are granted and denied to the database user, not the login. Permissions that have the scope of the whole instance of [!INCLUDE [ssNoVersion](../../../includes/ssnoversion-md.md)] (for example, the **CREATE ENDPOINT** permission) can be granted to a login.
48
50
49
51
> [!NOTE]
50
-
> When a login connects to [!INCLUDE [ssNoVersion](../../../includes/ssnoversion-md.md)], the identity is validated at the `master` database. Use contained database users to authenticate [!INCLUDE [ssNoVersion](../../../includes/ssnoversion-md.md)] and [!INCLUDE [ssSDS](../../../includes/sssds-md.md)] connections at the database level. When using contained database users, a login is not necessary. A contained database is a database that is isolated from other databases and from the instance of [!INCLUDE [ssNoVersion](../../../includes/ssnoversion-md.md)] or [!INCLUDE [ssSDS](../../../includes/sssds-md.md)] (and the `master` database) that hosts the database. [!INCLUDE [ssNoVersion](../../../includes/ssnoversion-md.md)] supports contained database users for both Windows and [!INCLUDE [ssNoVersion](../../../includes/ssnoversion-md.md)] authentication. When using [!INCLUDE [ssSDS](../../../includes/sssds-md.md)], combine contained database users with database level firewall rules. For more information, see [Contained Database Users - Making Your Database Portable](../../../relational-databases/security/contained-database-users-making-your-database-portable.md).
52
+
> When a login connects to [!INCLUDE [ssNoVersion](../../../includes/ssnoversion-md.md)], the identity is validated at the `master` database. Use contained database users to authenticate [!INCLUDE [ssNoVersion](../../../includes/ssnoversion-md.md)] and [!INCLUDE [ssSDS](../../../includes/sssds-md.md)] connections at the database level. When using contained database users, a login is not necessary. A contained database is a database that is isolated from other databases and from the instance of [!INCLUDE [ssNoVersion](../../../includes/ssnoversion-md.md)] or [!INCLUDE [ssSDS](../../../includes/sssds-md.md)] (and the `master` database) that hosts the database. [!INCLUDE [ssNoVersion](../../../includes/ssnoversion-md.md)] supports contained database users for both Windows and [!INCLUDE [ssNoVersion](../../../includes/ssnoversion-md.md)] authentication. When using [!INCLUDE [ssSDS](../../../includes/sssds-md.md)], combine contained database users with database level firewall rules. For more information, see [Make your database portable by using contained databases](../contained-database-users-making-your-database-portable.md).
51
53
52
-
## <aname="Permissions"></a> Permissions
54
+
<aid="Permissions"></a>
55
+
56
+
## Permissions
53
57
54
58
[!INCLUDE [ssNoVersion](../../../includes/ssnoversion-md.md)] requires **ALTER ANY LOGIN** or **ALTER LOGIN** permission on the server, or the **##MS_LoginManager##** fixed server role (SQL Server 2022 and later).
55
59
56
60
[!INCLUDE [ssSDS](../../../includes/sssds-md.md)] requires membership in the **loginmanager** role or the fixed server role, **##MS_LoginManager##**.
57
61
58
-
## <aname="SSMSProcedure"></a> Create a login using SSMS for SQL Server
62
+
<aid="SSMSProcedure"></a>
63
+
64
+
## Create a login using SSMS for SQL Server
59
65
60
66
1. In Object Explorer, expand the folder of the server instance in which you want to create the new login.
61
67
@@ -86,7 +92,7 @@ As a security principal, permissions can be granted to logins. The scope of a lo
86
92
87
93
1. When changing an existing password, select **Specify old password**, and then type the old password in the **Old password** box.
88
94
89
-
1. To enforce password policy options for complexity and enforcement, select **Enforce password policy**. For more information, see [Password Policy](../../../relational-databases/security/password-policy.md). This is a default option when **SQL Server authentication** is selected.
95
+
1. To enforce password policy options for complexity and enforcement, select **Enforce password policy**. For more information, see [Password Policy](../password-policy.md). This is a default option when **SQL Server authentication** is selected.
90
96
91
97
1. To enforce password policy options for expiration, select **Enforce password expiration**. **Enforce password policy** must be selected to enable this checkbox. This is a default option when **SQL Server authentication** is selected.
92
98
@@ -96,7 +102,7 @@ As a security principal, permissions can be granted to logins. The scope of a lo
96
102
97
103
1. To associate the login with a stand-alone asymmetric key, select **Mapped to asymmetric key** to, and then select the name of an existing key from the list.
98
104
99
-
1. To associate the login with a security credential, select the **Mapped to Credential** check box, and then either select an existing credential from the list or select **Add** to create a new credential. To remove a mapping to a security credential from the login, select the credential from **Mapped Credentials** and select **Remove**. For more information about credentials in general, see [Credentials (Database Engine)](../../../relational-databases/security/authentication-access/credentials-database-engine.md).
105
+
1. To associate the login with a security credential, select the **Mapped to Credential** check box, and then either select an existing credential from the list or select **Add** to create a new credential. To remove a mapping to a security credential from the login, select the credential from **Mapped Credentials** and select **Remove**. For more information about credentials in general, see [Credentials (Database Engine)](credentials-database-engine.md).
100
106
101
107
1. From the **Default database** list, select a default database for the login. `master` is the default for this option.
102
108
@@ -165,7 +171,7 @@ Specifies the default schema of the user. When a user is first created, its defa
165
171
Read-only attribute indicating whether the Guest account is enabled on the selected database. Use the **Status** page of the **Login Properties** dialog box of the Guest account to enable or disable the Guest account.
166
172
167
173
**Database role membership for:**_database_name_
168
-
Select the roles for the user in the specified database. All users are members of the **public** role in every database and can't be removed. For more information about database roles, see [Database-Level Roles](../../../relational-databases/security/authentication-access/database-level-roles.md).
174
+
Select the roles for the user in the specified database. All users are members of the **public** role in every database and can't be removed. For more information about database roles, see [Database-level roles](database-level-roles.md).
169
175
170
176
### Securables
171
177
@@ -242,7 +248,9 @@ Select this option to enable or disable this login. This option uses the `ALTER
242
248
**SQL Server authentication**
243
249
The check box **Login is locked out** is only available if the selected login connects using [!INCLUDE [ssNoVersion](../../../includes/ssnoversion-md.md)] authentication and the login has been locked out. This setting is read-only. To unlock a login that is locked out, execute `ALTER LOGIN` with the UNLOCK option.
244
250
245
-
## <aname="TsqlProcedure"></a> Create a login using Windows authentication with T-SQL
251
+
<aid="TsqlProcedure"></a>
252
+
253
+
## Create a login using Windows authentication with T-SQL
246
254
247
255
1. In **Object Explorer**, connect to an instance of [!INCLUDE [ssDE](../../../includes/ssde-md.md)].
248
256
@@ -275,17 +283,19 @@ The check box **Login is locked out** is only available if the selected login co
275
283
GO
276
284
```
277
285
278
-
For more information, see [CREATE LOGIN (Transact-SQL)](../../../t-sql/statements/create-login-transact-sql.md).
286
+
For more information, see [CREATE LOGIN](../../../t-sql/statements/create-login-transact-sql.md).
287
+
288
+
<aid="FollowUp"></a>
279
289
280
-
## <aname="FollowUp"></a> Follow up: Steps to take after you create a login
290
+
## Follow up: Steps to take after you create a login
281
291
282
292
The login can connect to [!INCLUDE [ssNoVersion](../../../includes/ssnoversion-md.md)] after creating a login, but doesn't necessarily have sufficient permission to perform any useful work. The following list provides links to common login actions.
283
293
284
-
- To have the login join a role, see [Join a Role](../../../relational-databases/security/authentication-access/join-a-role.md).
294
+
- To have the login join a role, see [Join a Role](join-a-role.md).
285
295
286
-
- To authorize a login to use a database, see [Create a Database User](../../../relational-databases/security/authentication-access/create-a-database-user.md).
296
+
- To authorize a login to use a database, see [Create a database user](create-a-database-user.md).
287
297
288
-
- To grant a permission to a login, see [Grant a Permission to a Principal](../../../relational-databases/security/authentication-access/grant-a-permission-to-a-principal.md).
298
+
- To grant a permission to a login, see [Grant a Permission to a Principal](grant-a-permission-to-a-principal.md).
0 commit comments