• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

How to create a User Account in Microsoft SQL Databse

Hi,
Can anyone explain how to creat A User Account in a SQL Database.
0
Computers4me
Asked:
Computers4me
1 Solution
 
Steve WalesSenior Database AdministratorCommented:
It's a two step process.

First you have to create a login to the instance.

That can be a SQL Server account (with a password) or you take take the Windows AD login and pass that through.

Then you create a user in the database connected to that login and grant appropriate privileges.

use master
go
create login [fred] from windows with default database=[master]
go
use demo
go
create user fred for login fred
go
grant select on table to fred

Open in new window


The user name and the login name do not have to be the same.  Make sure you grant object permissions to the user, not the login.

There are exceptions, for example you can make a login a system wide administrator for all databases on the instance.

From the documentation:

Creating a login: http://msdn.microsoft.com/en-us/library/aa337562.aspx
Creating a user: http://msdn.microsoft.com/en-us/library/ms173463.aspx
0
 
Ess KayEntrapenuerCommented:
you can also right click on the database, and use the graphic user interface
0
 
Computers4meAuthor Commented:
How would you Pass through an AD User account?
0
 
Steve WalesSenior Database AdministratorCommented:
If my domain is MYDOMAIN and my account is sjwales it would be:

create login [MYDOMAIN\sjwales] from windows with default database=[master]

Open in new window


All of this can be done from the SSMS GUI as well as indicated by esskayb2d.

The username could then be anything, drop the domain from user if you want, for example.

create user sjwales for login [MYDOMAIN\sjwales]

Open in new window


and then assign appropriate permissions to sjwales as needed.
0
 
Alpesh PatelAssistant ConsultantCommented:
In security tab create login as like

Create login
In database security node create user as like

create user
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now