SQL Server: CREATE USER statement

 CREATE USER statement 

This SQL Server tutorial explains how to use the SQL Server CREATE USER statement with syntax and examples.

Description

The CREATE USER statement creates a database user to log into SQL Server. A database user is mapped to a Login, which is an identity used to connect to a SQL Server instance.

Syntax

The syntax for the CREATE USER statement in SQL Server (Transact-SQL) is:

CREATE USER user_name FOR LOGIN login_name;

Parameters or Arguments

user_name

The name of the database user that you wish to create.

login_name

The Login used to connect to the SQL Server instance. Learn how to create a Login.

Note

  • Before creating a database user, make sure that you have first created a Login.
  • You can only map a Login to one user in each database in SQL Server, but you can map the Login to different user names for each database as long as it is a 1:1 ratio of Login to unique database.
  • See also the DROP USER statement.

Example

Let’s look at how to create a database user using the CREATE USER statements in SQL Server (Transact-SQL).

For example:

CREATE USER adglob FOR LOGIN adglob;

This CREATE USER example would create a new database user called adglob in SQL Server. It would use the adglob Login as the identity to connect to the SQL Server instance.

This Post Has One Comment

Leave a Reply