?
Solved

TO James   WITH GRANT OPTION;

Posted on 2014-12-15
7
Medium Priority
?
100 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 600 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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 1400 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
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.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

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