Create a user for SQL Server 2008?

前端 未结 3 1514
野的像风
野的像风 2021-02-08 07:54

I\'m using this code to create a new user.

/****** Object:  User [primebox] ******/
IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N\'primebox         


        
相关标签:
3条回答
  • 2021-02-08 08:36

    Logins are different things than users, here is how to create a new LOGIN.

    1. Right click SQL Server Management Studio and choose -> Run as adminstrator.

    2. Login normally with the default Windows Authentication.

    3. Choose Databases -> System Databases -> master. Click "New Query" button upper left.

    4. Paste this query in there. (for more info SQL login options see here):

      CREATE LOGIN youruser WITH PASSWORD = 'yourpassword'
      
    5. You should get this response:

      Command(s) completed successfully.
      
    6. Check to make sure it got added to dbo.syslogins

      select * from master.dbo.syslogins
      
    7. Close and restart SQL Management server (as administrator) and restart SQL Server itself by going to the SQL Server Configuration panel and clicking restart.

    8. In the object explorer click the main EL-PC\SQLEXPRESS -> Security -> Logins.

    9. Your newly created login should be there, right click and go to properties, you have to grant that user permission to visit the default database, and set a default database.

    10. Close SQL Server and login again with the SQL Server Authentication option and username/password. You should now be logged in with your new user.

    How to create a new user

    1. Start SQL Server Management Studio as administrator.
    2. Expand the database which you want to create the new database user.
    3. Right click the "Security" folder choose "New User", if the option isn't available you probably clicked the server's security folder.
    4. Add the name, and configurations, and click OK.
    0 讨论(0)
  • 2021-02-08 08:55

    In SQL Server, users are different to logins.

    To create a user for a database, you first have to create a login for the server using the create login syntax

    0 讨论(0)
  • 2021-02-08 09:00

    In addition you can create a new login also by UI of the Sql Server Management Studio by clicking on the main security folder enter image description here

    and after creating the user

    0 讨论(0)
提交回复
热议问题