Solved

TO James   WITH GRANT OPTION;

Posted on 2014-12-15
7
97 Views
Last Modified: 2014-12-24
hi experts:

GRANT UPDATE ON Marketing.Salesperson
  TO James
  WITH GRANT OPTION;
GO

As I can get the list of users to whom James grant permissions (WITH GRANT OPTION)
0
Comment
Question by:enrique_aeo
7 Comments
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 40503010
Great; so, what's your question?
0
 
LVL 22

Assisted Solution

by:Steve Wales
Steve Wales earned 150 total points
ID: 40503087
See the documentation for sys.database_permissions: http://msdn.microsoft.com/en-us/library/ms188367.aspx

Something like this will show you who granted what to whom:
select class, class_desc, object_name(major_id), object_name(minor_id), grantee_principal_id, b.name, grantor_principal_id, c.name, permission_name, a.type, a.state, a.state_desc
from sys.database_permissions a
join sys.database_principals b on a.grantee_principal_id = b.principal_id
join sys.database_principals c on a.grantor_principal_id = c.principal_id

Open in new window


Permissions granted with grant option would have a 'W' in state (grant with grant option), rather than 'G' (grant)
0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 40503707
DECLARE @grantor_name sysname
SET @grantor_name = 'James'

SELECT
    USER_NAME (dprm.grantee_principal_id) AS Granted_To_UserName,
    dprm.class_desc AS Object_Type,
    OBJECT_NAME(dprm.major_id) AS Object_Name,
    CASE WHEN dprm.minor_id = 0 THEN '' ELSE COL_NAME(dprm.major_id, dprm.minor_id ) END AS Column_Name,
    dprm.permission_name, dprm.state_desc
FROM sys.database_permissions dprm
WHERE dprm.grantor_principal_id = (
    SELECT grantor_principal_id
    FROM sys.database_principals dprn
    WHERE dprn.name = @grantor_name
    )
ORDER BY
   Granted_To_UserName, Object_Type, Object_Name, Column_Name
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:enrique_aeo
ID: 40507962
DROP LOGIN [James]
DROP USER [James]
GO
DROP LOGIN [JamesJunior]
DROP USER [JamesJunior]

-- Create a login and add user to MarketDEev
CREATE LOGIN [James]
WITH PASSWORD = 'Pa$$w0rd'
, CHECK_POLICY = OFF
GO
 
USE [MarketDev]
GO
 
CREATE USER [James] FOR LOGIN [James]
WITH DEFAULT_SCHEMA = [dbo]
GO

--1 Otorgando permisos a Jhon
USE MarketDev;
GO

GRANT SELECT ON Marketing.Salesperson
  TO James
  WITH GRANT OPTION;
GO


EXECUTE AS USER = 'James'
SELECT * FROM  Marketing.Salesperson
REVERT

--Creando al hijo de James
CREATE LOGIN [JamesJunior]
WITH PASSWORD = 'Pa$$w0rd'
, CHECK_POLICY = OFF
GO
 
USE [MarketDev]
GO
 
CREATE USER [JamesJunior] FOR LOGIN [JamesJunior]
WITH DEFAULT_SCHEMA = [dbo]
GO

--Otorgando permisos
EXECUTE AS USER = 'James'
GRANT SELECT ON Marketing.Salesperson
  TO JamesJunior
;
GO
REVERT

EXECUTE AS USER = 'JamesJunior'
SELECT * FROM  Marketing.Salesperson
REVERT

--Consultando 01
DECLARE @grantor_name sysname
SET @grantor_name = 'James'

I need to see James grant users permissions
0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 350 total points
ID: 40507999
Sorry, I had one copy/paste error in my code:


DECLARE @grantor_name sysname
 SET @grantor_name = 'James'

 SELECT
     USER_NAME (dprm.grantee_principal_id) AS Granted_To_UserName,
     dprm.class_desc AS Object_Type,
     OBJECT_NAME(dprm.major_id) AS Object_Name,
     CASE WHEN dprm.minor_id = 0 THEN '' ELSE COL_NAME(dprm.major_id, dprm.minor_id ) END AS Column_Name,
     dprm.permission_name, dprm.state_desc
 FROM sys.database_permissions dprm
 WHERE dprm.grantor_principal_id = (
     SELECT dprn.principal_id
     FROM sys.database_principals dprn
     WHERE dprn.name = @grantor_name
     )
 ORDER BY
    Granted_To_UserName, Object_Type, Object_Name, Column_Name
0
 

Author Comment

by:enrique_aeo
ID: 40508006
no show rows
0
 

Author Comment

by:enrique_aeo
ID: 40508060
my mistake
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
backup job space check 4 44
query question 12 32
Use column to search string column 2 11
Substring works but need to tweak it 14 16
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question