随笔 - 229  文章 - 2  评论 - 511  阅读 - 84万

FAQ:security

1 How to grant "create table" permission to a user for a speical database

--step 1: create a login account
use tempdb
go
create login l1 with password='p@ssword1'
go

--step 2:create a user account ,and associate it with the login account
create user u1 for login l1

--step 3:Requires CREATE TABLE permission in the database and ALTER permission on the schema in which the table is being created.
grant create table to u1 
go
GRANT alter ON SCHEMA::dbo TO u1;


--step 4: create a table as u1
execute as user='u1'
go
create table table1
(
  col 
int
)




2 How to grant "select" permission to a user for a speical database
--step 1: create a table and create a login account in tempdb database
use tempdb
go
create table table1
(
   col 
int
)
go
create login l1 with password='p@ssword1'
go

--step 2:create a user account ,and associate it with the login account
create user u1 for login l1

--step 3:grant select permission for database to user
grant select  to u1 


---step 4 :select 
execute as user='u1'
go
select * from table1

3 How to grant "select" permission to a user for a speical table
--step 1: create a table and create a login account in tempdb database
use tempdb
go
create table table1
(
   col 
int
)
go
create table table2
(
   col 
int
)
go
create login l1 with password='p@ssword1'
go

--step 2:create a user account ,and associate it with the login account
create user u1 for login l1

--step 3:grant select permission for database to user
grant select on dbo.table1 to u1 


---step 4 :select 
execute as user='u1'
go
select * from table1
go
select * from table2---throw an error



4 Impersonation Permission
For user impersonation, you need to connect to the appropriate DB and grant IMPERSONATE permission to the user using the following syntax:

 

GRANT IMPERSONATE ON USER::<<impersonated_context_user_name>>   TO <<grantee_user_name>>

for example:

GRANT IMPERSONATE ON USER::[user_to_be_impersonated] TO [user1]
go

For login impersonation, you need to connect to master DB and then grant the IMPERSONATE permission to the login:

GRANT IMPERSONATE ON LOGIN::<<impersonated_context_login_name>> 

  
TO <<grantee_login_name>>

for example:

GRANT IMPERSONATE ON LOGIN::[login_to_be_impersonated] TO [login1]

go

5 alter schema
--The following example modifies the schema HumanResources by transferring the table Address from schema Person into the schema.
USE AdventureWorks;
GO
ALTER SCHEMA HumanResources TRANSFER Person.Address;
GO


6  Changing ownership of a schema

--In the following example, a new user, Jon, is created in the AdventureWorks database. Jon is granted ownership of the Auditing schema in the AdventureWorks database. Then the user called Marjorie is dropped from the AdventureWorks database.


USE AdventureWorks;
GO
/* Create a new user in the database */
CREATE LOGIN Jon
    
WITH PASSWORD = '1fdKJl3$nlNv3049jsBB';
USE AdventureWorks;
CREATE USER Jon FOR LOGIN Jon
GO
ALTER AUTHORIZATION ON SCHEMA::Auditing TO Jon;
posted on   stswordman  阅读(309)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
< 2007年9月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 1 2 3 4 5 6

点击右上角即可分享
微信分享提示