How to create a user and grant permissions in SQL Server?
To create a user and grant permissions in SQL Server, you can follow these steps:
- First, log in to SQL Server Management Studio (SSMS) using an administrator account.
- Choose the database where you want to create the user, then right-click on the database and select “New Query”.
- Enter the following code in the query window to create a new user and assign a password:
CREATE LOGIN [用户名] WITH PASSWORD = '密码';
Please replace “username” with the username you wish to create, and replace “password” with the user’s password.
- Next, create a database user for the newly created user.
USE [您的数据库名称];
CREATE USER [用户名] FOR LOGIN [用户名];
- Finally, grant permissions to the user. You can use the GRANT statement to grant different permissions to the user, such as SELECT, INSERT, UPDATE, DELETE, and so on. For example, if you want to give a user SELECT permission on a specific table, you can use the following command:
USE [您的数据库名称];
GRANT SELECT ON [表名] TO [用户名];
By following the steps above, you can successfully create a user and assign permissions. Please note that in order to complete these actions, you need to have sufficient privileges.