Problem: How to give
permissions for executing a procedure to specific database user?
Solution: GRANT
Grants permissions on a securable to a principal. The general
concept is to GRANT <some permission> ON <some object> TO <some
user, login, or group>. For a general discussion of permissions,
To know more about a database user please go through this
article. What
is a database user
Syntax:
GRANT { ALL [
PRIVILEGES ] }
| permission [ (
column [ ,...n ] ) ] [ ,...n ]
[ ON [ class ::
] securable ] TO principal [ ,...n ]
[ WITH GRANT
OPTION ] [ AS principal ]
Example:
In this example, I would like to show we can Grant a user to
execute on a procedure to a newly created role.
CREATE ROLE proc_tester
GO
GRANT EXECUTE ON
[dbo].[UpdTableBbyDate] TO proc_tester
GO
ALTER ROLE proc_tester ADD MEMBER TestUser
GO
--query
to see the roles and members are added.
select u.name as
Rolename,u1.name
as membername from
sys.database_role_members m
INNER JOIN sys.database_principals
u
ON m.role_principal_id=u.principal_id
INNER JOIN sys.database_principals
u1
ON m.member_principal_id=u1.principal_id
where u.name='proc_tester'
Results:
Rolename
|
membername
|
proc_tester
|
TestUser
|
0 comments:
Post a Comment