Solved

TO James   WITH GRANT OPTION;

Posted on 2014-12-15
7
99 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

717 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