How to use sp_addlogin and sp_adduser

  • Can someone please help me in rewriting the following code using sp_addlogin and sp_adduser?

    CREATE LOGIN [Domain\New_AD_group] FROM WINDOWS WITH DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english]

    go

    USE Test

    go

    create user [Domain\New_AD_group] from login [Domain\New_AD_group]

    go

    EXEC sp_addrolemember N'NEW_role', N'Domain\New_AD_group'

    go

  • I'd recommend using the code that you listed instead.

    sp_addlogin is being deprecated.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • SQLRNNR (6/27/2012)


    I'd recommend using the code that you listed instead.

    sp_addlogin is being deprecated.

    I wish I could but our dev machine is SQL 2000(with Enterprise Manager) and when I run create login, it's failing.

  • Here's the Syntax

    sp_addlogin [ @loginame = ] 'login'

    [ , [ @passwd = ] 'password' ]

    [ , [ @defdb = ] 'database' ]

    [ , [ @deflanguage = ] 'language' ]

    [ , [ @sid = ] sid ]

    [ , [ @encryptopt = ] 'encryption_option' ]

    You already have the following

    CREATE LOGIN [Domain\New_AD_group] FROM WINDOWS WITH DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english]

    From those two sets, only two parameters match, I think you can see which they are

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • SQLRNNR (6/27/2012)


    Here's the Syntax

    sp_addlogin [ @loginame = ] 'login'

    [ , [ @passwd = ] 'password' ]

    [ , [ @defdb = ] 'database' ]

    [ , [ @deflanguage = ] 'language' ]

    [ , [ @sid = ] sid ]

    [ , [ @encryptopt = ] 'encryption_option' ]

    You already have the following

    CREATE LOGIN [Domain\New_AD_group] FROM WINDOWS WITH DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english]

    From those two sets, only two parameters match, I think you can see which they are

    I tried to do

    EXEC sp_addlogin '[DOMAIN\New_ad_group]' -- gave me syntax error

    EXEC sp_addlogin 'DOMAIN\New_ad_group' -- gave me syntax error

    but when I user sp_grantlogin, it gave me no errors...here's what I ran

    EXEC sp_grantlogin '[DOMAIN\New_ad_group]'

    How is it possible?

  • What is the exact error you received?

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • SQLRNNR (6/27/2012)


    What is the exact error you received?

    'Domain\New_ad_group' is not a valid name because it contains invalid characters.

  • And when you use the brackets?

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • SQLRNNR (6/27/2012)


    And when you use the brackets?

    Same error.

  • d'oh

    I missed a piece in the documentation. addlogin is for SQL logins only. Grantlogin is for adding windows accounts. That is the reason you were getting the errors.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • use sp_grantlogin to create windows users or groups:

    sp_grantlogin @loginame = 'domain\users or groups'

    in SQL2000, you need using sp_grantlogin to add windows users or groups

    http://technet.microsoft.com/en-us/library/aa933411(v=sql.80).aspx

  • don't know hwo to delete it ...

Viewing 12 posts - 1 through 11 (of 11 total)

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