Problem: How to dis allow a
database user not to access certain objects or schema?
Solution:
DENY
Denies a permission to a principal. Prevents that principal
from inheriting the permission through its group or role memberships.
To know more about a database user please go through this
article. What
is a database user
Syntax:
-- Simplified
syntax for DENY
DENY { ALL [ PRIVILEGES ] }
| <permission> [ ( column [ ,...n ] ) ] [ ,...n ]
[ ON [ <class> :: ]
securable ]
TO principal [ ,...n ]
[ CASCADE] [ AS principal ]
[;]
<permission> ::=
{ see the tables below }
<class> ::=
{ see the tables below }
Example:
In this example, I would like to show we can deny a user to
not access specific table.
--
disallow to select from table
DENY SELECT ON
OBJECT::dbo.Address TO TestUser;
GO
`--Check
the content of the table.
SELECT * FROM
dbo. Address
Results:
Example 2:
In this example, I would like to show how we can disallow a user to ex
--
disallow to execute procedure
DENY EXECUTE ON
OBJECT::dbo.[UpdTableBbyDate] TO
TestUser;
GO
GO
--Execute
the procedure from the user login.
USE [DB]
GO
DECLARE @return_value int
EXEC @return_value = [dbo].[UpdTableBbyDate]
@InputDate = N'06/26/2017'
SELECT 'Return
Value' = @return_value
GO
Results:
0 comments:
Post a Comment