Solved

TO James   WITH GRANT OPTION;

Posted on 2014-12-15
7
92 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
Comment Utility
Great; so, what's your question?
0
 
LVL 22

Assisted Solution

by:Steve Wales
Steve Wales earned 150 total points
Comment Utility
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:ScottPletcher
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:enrique_aeo
Comment Utility
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:
ScottPletcher earned 350 total points
Comment Utility
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
Comment Utility
no show rows
0
 

Author Comment

by:enrique_aeo
Comment Utility
my mistake
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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
Via a live example, show how to shrink a transaction log file down to a reasonable size.

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now