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