SQL Server database creation account

SQL Server database creation account


Create User Roles and Authorizations in SQL Server

Prepare to create a zry database account to manage the database mydb.

1. First, at the SQL Server server level, create a login account (create login)

create login zry with password=‘zryhappy’,default_database=mydb

Note: The login account name is 'zry', the login password is 'zryhappy', and the default connection database is 'mydb', which can connect to the database, but cannot access database objects.


2. Create a database user (create user)

Create a database user for the login account:

create user zry for login zry with default_schema=dbo

Note: The newly created database user can find the newly created zry under the user in the security of the mydb database. The default schema of the specified database user 'zry' is 'dbo'.


3. Give the database user 'zry' permission by adding the database role:

exec sp_addrolemember 'db_owner','zry'

Note: Give the database user 'zry' 'db_owner' permission, at this point, zry can fully manage the objects in the database mydb.


4. If you want the SQL Server login account 'zry' to access multiple databases, such as mydb2. You can make sa execute the following statement:

use mydb2

go

create user zry for login zry with default_schema=dbo

go

exec sp_addrolemember 'db_owner' ,'zry'

go

At this point, zry can have two databases mydb, mydb2 management authority.


--------Create account---------------------------------------- -------------------------------------------------------

1. First create a database zry, which can be created manually

2. Create account zry and execute the following sql

create login zry with psssword='zryhappy',default_database=zry

create user zry for login zry with default_schema=dbo

exec sp_addrolemember 'db_owner' , 'zry'

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


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324848951&siteId=291194637