How to create sql Login by script.


To create sql login user follow the scripts below :

First have to login to sql management studio with other user who have the permission to create user or by Windows authentication

and then run the following scripts :

CREATE LOGIN DesiredUserName WITH PASSWORD = 'DesiredUserPassword';

Now to map this login user to a database use the following script:

USE  dbNewDB
 GO
 CREATE USER DesiredUserName FOR LOGIN DesiredUserName WITH DEFAULT_SCHEMA=[dbo]
 GO       
 GRANT CONNECT,CONTROL to DesiredUserName
Advertisements

One Response to How to create sql Login by script.

  1. Paul says:

    Logged into Studio Express by Windows Authentication.

    When I try to create a new user I get:
    “User does not have permission to perform this action.”

    My problem is that I can restore a BAK file from another database via Studio Express, but then I can’t access the restored database, because it has a username and password.

    I am trying to create the same username and password via Studio Express but get the error above.

    How can I access the restored database?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: