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 2007-09-26 14:54  stswordman  阅读(308)  评论(0编辑  收藏  举报