MS SQL Server Concepts and Programming Question:
Download Job Interview Questions and Answers PDF
How To Create a User Name in a Database?
Answer:
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".
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".
Download MS SQL Server Interview Questions And Answers
PDF
Previous Question | Next Question |
How To Delete a Login Name in MS SQL Server? | How To List All User Names in a Database? |