sql 創建新用戶並授權

use Charges--使用的數據庫

--創建登陸名 

create Login danzhao             --用戶

with password = 'charge123',           --密碼

DEFAULT_DATABASE = charges,      --默認數據庫

CHECK_POLICY = OFF;         --強制密碼策略

go

--爲登錄 danzhao 在數據庫 charges 中添加安全賬戶 danzhao

exec sp_grantdbaccess 'danzhao','danzhao'

go
  
  
-- 授予角色執行存儲過程AddNewStudent的權限  
grant 
exec on AddNewStudent
to danzhao;  
  
-- 授予角色執行存儲過程GetStudentSecurityCode的權限  
grant 
exec on GetStudentSecurityCode
to danzhao; 



如果賦予的權限要多次使用,則可以先創建角色,再將權限賦予角色,最後將角色賦予用戶。


create role execProc

  
-- 授予角色執行AddNewStudent的權限  
grant 
exec on AddNewStudent
to execProc;
  
-- 授予角色執行GetStudentSecurityCode的權限  
grant 
exec on GetStudentSecurityCode
to execProc; 
grant execProc to danzhao

刪除權限就很簡單了

revoke exec from danzhao








發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章