Use mydb
Go
-- 1. Create a test user
-- 1.1 add login user and password
Exec sp_addlogin n 'Tony ', '123'
-- 1.2 make it a legal user of the current database
Exec sp_grantdbaccess n 'Tony'
-- 2. Set operation authorization
-- 2.1 Grant all permissions on your own database
Exec sp_addrolemember n 'db _ owner', N 'Tony'
-- 2.2: Set specific operation Permissions
-- Grant Tony the operation permission on all user tables.
Grant select, insert, update, delete to Tony
-- Authorize Tony select to update to a specific table
Grant select, update on TB to Tony
-- Authorize Tony select to update to a specific table and Column
Grant select, update on TB (ID, col) to Tony
-- Disable Tony's permission to operate all user tables.
Deny select, insert, update, delete to Tony
-- Disable Tony select and update to a specific table
Deny select, update on TB to Tony
-- Disable Tony select and update to specific tables and columns.
Deny select, update on TB (ID, col) to Tony
-- Delete Tony's authorization information for all user tables
Revoke select, insert, update, delete to Tony
-- Grant Tony operation permissions for creating tables, views, and stored procedures.
Grant create table, create view, create proc to Tony
-- Disable Tony's permission to create tables, views, and stored procedures.
Deny create table, create view, create proc to Tony
-- Delete Tony's authorization information for creating tables, views, stored procedures, etc.
Revoke create table, create view, create proc to Tony
Go
-- Note: For more authorization information, refer to the "database Permissions" column in the attached table.
-- 3. Delete the test user
Exec sp_revokedbaccess n 'Tony '-- removes the user's access permission to the database.
Exec sp_droplogin n 'Tony '-- delete a logon user
Go
Appendix:
Database Permissions |
Implicit permissions of database Permissions |
Implicit server Permissions |
Alter |
Control |
Alter any database |
Alter any application role |
Alter |
Control Server |
Alter any assembly |
Alter |
Control Server |
Alter any asypolicric key |
Alter |
Control Server |
Alter any certificate |
Alter |
Control Server |
Alter any contract |
Alter |
Control Server |
Alter any database DDL trigger |
Alter |
Control Server |
Alter any database Event Notification |
Alter |
Alter any event notification |
Alter any DataSpace |
Alter |
Control Server |
Alter any Fulltext catalog |
Alter |
Control Server |
Alter any message type |
Alter |
Control Server |
Alter any remote service binding |
Alter |
Control Server |
Alter any role |
Alter |
Control Server |
Alter any route |
Alter |
Control Server |
Alter any Schema |
Alter |
Control Server |
Alter any service |
Alter |
Control Server |
Alter any invalid Ric key |
Alter |
Control Server |
Alter any user |
Alter |
Control Server |
Authenticate |
Control |
Authenticate Server |
Backup Database |
Control |
Control Server |
Backup log |
Control |
Control Server |
Checkpoint |
Control |
Control Server |
Connect |
Connect Replication |
Control Server |
Connect Replication |
Control |
Control Server |
Control |
Control |
Control Server |
Create Aggregate |
Alter |
Control Server |
Create assembly |
Alter any assembly |
Control Server |
Create asypolicric key |
Alter any asypolicric key |
Control Server |
Create Certificate |
Alter any certificate |
Control Server |
Create contract |
Alter any contract |
Control Server |
Create Database |
Control |
Create any database |
Create Database DDL Event Notification |
Alter any database Event Notification |
Create DDL Event Notification |
Create default |
Alter |
Control Server |
Create Fulltext catalog |
Alter any Fulltext catalog |
Control Server |
Create Function |
Alter |
Control Server |
Create Message Type |
Alter any message type |
Control Server |
Create procedure |
Alter |
Control Server |
Create queue |
Alter |
Control Server |
Create remote service binding |
Alter any remote service binding |
Control Server |
Create role |
Alter any role |
Control Server |
Create route |
Alter any route |
Control Server |
Create rule |
Alter |
Control Server |
Create Schema |
Alter any Schema |
Control Server |
Create Service |
Alter any service |
Control Server |
Create foreign Ric key |
Alter any invalid Ric key |
Control Server |
Create Synonym |
Alter |
Control Server |
Create Table |
Alter |
Control Server |
Create type |
Alter |
Control Server |
Create View |
Alter |
Control Server |
Create XML Schema collection |
Alter |
Control Server |
Delete |
Control |
Control Server |
Execute |
Control |
Control Server |
Insert |
Control |
Control Server |
References |
Control |
Control Server |
Select |
Control |
Control Server |
Showplan |
Control |
Alter trace |
Subscribe query configurications |
Control |
Control Server |
Take Ownership |
Control |
Control Server |
Update |
Control |
Control Server |
View database state |
Control |
View server state |
View Definition |
Control |
View any definition |
Share: