Avatar of enrique_aeo
enrique_aeo
 asked on

TO James WITH GRANT OPTION;

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)
Microsoft SQL Server

Avatar of undefined
Last Comment
enrique_aeo

8/22/2022 - Mon
Vadim Rapp

Great; so, what's your question?
SOLUTION
Steve Wales

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Scott Pletcher

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
enrique_aeo

ASKER
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
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER CERTIFIED SOLUTION
Scott Pletcher

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
enrique_aeo

ASKER
no show rows
enrique_aeo

ASKER
my mistake