Add new user in SQL server 2000/2005 through script

  • Hello friends,

    Is there any way to add a new db user in sql 2000/2005 through script ?

    If yes please provide this sample script..

  • Here is the command for adding user on SQL server 2000/2005

    --2000

    exec sp_addlogin @loginame='NewLoginName',

    @passwd='The Password',

    @defdb='Default Database Name', --Optional

    @deflanguage='Language' --Optional

    exec sp_adduser @loginame='NewLoginName',

    @name_in_db='NewUserName',

    --2005

    CREATE LOGIN NewLoginName

    WITH PASSWORD = 'The Password';

    USE AdventureWorks2008R2;

    CREATE USER NewLoginName FOR LOGIN NewLoginName;

    GO

  • sumitagarwal781 (2/6/2012)


    Thanks a lot

  • what is the difference between 2000 user and 2005 user ?

    thanks in advance

    sri

  • Conceptually both are same.

    Login lets you connects to the server

    and User has the permissions inside the database.

    Only difference is in 2000 the user and schema are clubbed.

    In 2005 they are independent

    ----------------------------------------------------------------------------------------------------------------------------------------------------
    Roshan Joe

    Jeff Moden -Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • To create a database user account for an existing login,

    sp_grantdbaccess @loginname = 'loginname'

    ----------------------------------------------------

Viewing 6 posts - 1 through 5 (of 5 total)

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