SQL

How To Create User In SQL

In this article, we will learn how to create a user in SQL.

To create a user for a database, we first have to create a new login for the server or we can use an existing one.

Please check How To Create Login In SQL, to create a new login.

There are 2 ways to create a new user in SQL Server.

  • Using T-SQL:

Syntax

CREATE USER USER_NAME FOR LOGIN LOGIN_NAME;

Example

The subsequent statement would create a user named TestUser for login named TestLogin:

CREATE USER TestUser FOR LOGIN TestLogin;

 

  • Using SSMS (SQL Server Management Studio):

Let’s follow the below steps to create a new database user in SQL Server.

Step 1:

Firstly, Open Microsoft SQL Server Management Studio and decide in which existing database (DBEmployee) you want to create a new user.

Step 2:

Now, Expand your database (DBEmployee) and Security directory.

Then right-click on Users directory and click on the New User… option.

Step 3:

Now, ‘Database User – New‘ dialogue box will open. Choose SQL user with login from the User type drop-down list and then enter your User name (TestUser) and Login name (TestLogin) and then click on the OK button.

Step 4:

Now, refresh Object Explorer and check new user (TestUser) is created.

 

Also, check How To Use NULL Functions In SQL

Yasin Panwala

Yasin Panwala is a Web Developer and Author at TheCodeHubs. He has experience in Web Developing and Designing and also in Writing. He has got his skills in working on technologies like .NET Core, ADO.NET, AJAX, Angular, AngularJS, ASP.NET, ASP.NET MVC, Bootstrap, C#, CSS, Entity Framework, Express.js, GraphQL, HTML, JavaScript, JQuery, JSON, LINQ, Microsoft Office, MongoDB, MySQL, Node.js, PostgreSQL, SQL, SQL Server, TypeORM, TypeScript, Visual Basic .NET, Web API. He also got his skills in working with different integration and some known versioning tools. He is always ready to learn new things and he always tries his best on tasks that are assigned to him and gives the best possible outputs.

Recent Posts

Testing hk

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Operation

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

TETS NEW

test

2 years ago