Answers

Question and Answer:

  Home  MS SQL Server

⟩ How To Create a User Name in a Database?

User names are security principals at the database level. If you want to allow a login name to access a specific database, you need to create a user name in that database and link it to the login name.

Creating a user name can be done by using the "CREATE USER" statement as shown in this tutorial exercise:

-- Login with "sa"

-- Create a login

CREATE LOGIN ggl_Login WITH PASSWORD = 'IYF'

GO

-- Select a database

USE GlobalGuideLineDatabase;

GO

-- Create a user and link it to a login

CREATE USER ggl_User FOR LOGIN ggl_Login;

GO

Login name "ggl_Login" should be able to access database "GlobalGuideLineDatabase" through user name "ggl_User".

 138 views

More Questions for you: