CREATE LOGIN script

  • Hi,

    How to specify permissions for a new Login that you create using the

    CREATE LOGIN script for SQL Server 2005 ??

    CREATE LOGIN [AccountName] with PASSWORD n'asdfasdf'

    How to give permission option in above list

  • Hi there and welcome to SSC. Didnt really understand your request but assuming you talking about how to script new windows logins in SQL 2005, please see below:

    USE [master]

    CREATE LOGIN [MYDOMAIN\mydomain_user] FROM WINDOWS WITH DEFAULT_DATABASE=[{set default database here}]

    Once you have created your user, you need to give them access to databases and permissions. For this see below:

    USE [A_DATABASE]

    CREATE USER [MYDOMAIN\mydomain_user] FOR LOGIN [MYDOMAIN\mydomain_user]

    -- Now set the database permissions

    USE [A_DATABASE]

    EXEC sp_addrolemember N'db_datareader', N'MYDOMAIN\mydomain_user'

    EXEC sp_addrolemember N'db_datawriter', N'MYDOMAIN\mydomain_user'

    There are of course other options you can set when creating the login. My advice if your new is to use the GUI to set up all the options you want to incoperate (in your script) and the use the built in scripting tool.

    This will give you the basic script which you can the customise.

    Hope this helps 🙂

    Adam Zacks-------------------------------------------Be Nice, Or Leave

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply