The CREATE USER command in SQL Server

This article will show you in detail how to use the CREATE USER command in SQL Server, with specific syntax and examples to better visualize and capture commands.

Describe the CREATE USER command in SQL Server

CREATE USER creates the user database to log into SQL Server. A user database will be mapped to the Login, identifier used to connect to a specific SQL Server instance.

The syntax of CREATE USER command in SQL Server

The CREATE USER command has the following syntax:

 CREATE USER user_name FOR LOGIN login_name; 

Parameters:

  1. user_name: The name of the database user you want to create.
  2. login_name: The Login name is used to connect to a specific SQL Server.

Note:

  1. Before creating a database user, make sure you have created the Login before.
  2. You can only map a Login to a user in each database in SQL Server, but you can also map Login to different user names for each database as long as it is a 1: 1 relationship of Login with a single database.

Example of CREATE USER command in SQL Server

Suppose you want to create a database user named quantrimangcom in SQL Server, and use the previously created Login named qtm as an identifier to connect to a specific SQL Server, we will use the CREATE USER command as follows:

 CREATE USER quantrimangcom FOR LOGIN qtm; 

In the next article we will learn how to change the password in SQL Server.

Previous article: Find Login in SQL Server

Next lesson: Change the password in SQL Server

3.5 ★ | 2 Vote

May be interested

  • Instructions for installing SQL Server 2017 step by stepPhoto of Instructions for installing SQL Server 2017 step by step
    sql server 2017 comes with new features in the installation process. it now supports the machine learning service for r and python. it also includes ssis scale out master and scale out worker.
  • DROP USER command in SQL ServerPhoto of DROP USER command in SQL Server
    this article will show you in detail how to use the drop user command in sql server with specific syntax and examples to better visualize and capture commands.
  • Find User in SQL ServerPhoto of Find User in SQL Server
    do any queries on sql server return all user created?
  • Use annotations in SQL ServerPhoto of Use annotations in SQL Server
    this article will show you how to use annotations in sql server statements.
  • LITERAL in SQL ServerPhoto of LITERAL in SQL Server
    the article details how to use literal - hang (strings, integers, decimals, and datetime values) in sql server.
  • Declare variables in SQL ServerPhoto of Declare variables in SQL Server
    sql server fully exists the concepts of data types, variables and declarations of variables as other programming languages. the article will learn how to declare a variable, multiple variables and assign default values ​​to variables in sql server.