SQL Server basic permission management [memo]

Source: Internet
Author: User

 

In SQL ServerStored ProcedureManagementLogin Name, Including:

Sp_addlogin sp_droplogin sp_helplogins

Sp_grantlogin sp_revokelogin sp_denylogin

Note thatStored ProcedureRequiredInMaster Database.

 

BelowCodeImplement simple three-tier permissions:

Use S100801a
Go

-- ====================================== Database logon ====================== ==========
-- Add a logon user (sp_addlogin 'username', 'Password', 'default database name ')
Exec Sp_addlogin n ' XG ' , N ' Xg123 '
-- Or
Exec Sp_addlogin n ' XG ' , N ' Xg123 ' , N ' Master '

-- remove a logon user
exec sp_droplogin n ' XG '

-- ================================== database access ============== ===========

-- Add a database access user (sp_grantdbaccess 'username', 'database name ')
use s100801a
go
exec sp_grantdbaccess n ' XG ' , n ' db_xg '

--Remove Database Access Users
ExecSp_revokedbaccess n'Db_xg'

-- ====================================== Database permissions ====================== ==========

-- Grant all permissions to the database (sp_addrolemember 'Role ', 'user ')
Exec Sp_addrolemember n ' Db_owner ' , N ' Db_xg '
-- You can only access your own database and the Public tables of guest users.

-- Remove all permissions to the database (sp_droprolemember 'Role ', 'user ')
Exec Sp_droprolemember n ' Db_owner ' , N ' Db_xg '

/* ===================================================== ==========================================
Important:
In a later version of Microsoft SQL Server, the access permission function using 'System stored process' will be deleted.
To avoid using this function in the new development work, you should modify the method to implement this function.
========================================================== ========================================= */

 

The implementation method is as follows: -- The following example first creates a Server login name named 'xg' with a password,
-- Then, create the user 'abo _ xg' corresponding to the login name 'xg' in the database '100801a '.

-- Add Login User
Create Login XG With Password =   ' Xg123 ' ;

--Remove Login User
DropLogin XG;

--Add Database Access Users
UseS100801a;
Create UserDbo_xgForLogin XG;
Go 

-- Remove Database Access Users
Use S100801a;
Drop   User Dbo_xg;
Go
 
-- Distribution permission
Grant   Insert , Select , Update , Delete   On Students To   Public   -- Dbo_xg
Revoke   Insert , Select , Update , Delete   On Students From   Public   -- Dbo_xg

-- Grant all on students to aa_0801
-- Revoke all on students from aa_0801

When you use SQL commands to assign permissions, you can use commands such as grant, deny, and revoke.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.