Grant the user SELECT, INSERT, UPDATE, DELETE, EXECUTE and VIEW DEFINITION rights to the database (or the schema). This will grant the user the rights to all the objects within the database (or the schema).
You'll probably also need to give them rights like ALTER ANY OBJECT within the database as well so that they can modify the objects.
Not sure where you've stumbled along the way, but this works for me:
CREATE LOGIN permtest WITH PASSWORD = 'x', CHECK_POLICY = OFF;
GO
USE somedatabase;
GO
CREATE USER permtest FROM LOGIN permtest;
GO
According to this page, the user needs SELECT
permission on sys.sql_expression_dependencies
, and VIEW DEFINITION
on the database.
In my experimentation, the following allowed the user to select from the view, but it returned 0 rows, because they don't have the ability to view definition (which includes dependency chains):
GRANT SELECT ON sys.sql_expression_dependencies TO permtest;
In order to actually see any relationships in somedatabase
, I also had to add the following:
GRANT VIEW DEFINITION ON DATABASE::floob TO permtest;
I could not find any way to make that more granular (VIEW
/DENY
definition worked for individual objects, but without the database-level right, I still couldn't see any rows in the catalog view, and DENY
did not prevent the objects from showing up in the catalog view nor did it even prevent me from viewing the definition). I feel like SQL Server would have a hard time resolving that granularity anyway - if you had a view that referenced a table, how should the catalog view look if you have grant on the view and deny on the table, or vice versa?
If you don't want to grant VIEW DEFINITION
on the database, then create procedures that use EXECUTE AS OWNER
, select (filtered?) rows from the catalog view, and give the users (and of course, that could also be a role) execute permissions on the procedure.
CREATE PROCEDURE dbo.GetDependencies
WITH EXECUTE AS OWNER
AS
BEGIN
SELECT is_schema_bound_reference --, ...
FROM sys.sql_expression_dependencies;
END
GO
GRANT EXECUTE ON dbo.GetDependencies TO permtest;
Best Answer
If you suspect the user is an entity owner, you can confirm that by running this query, which shows all objects in the current database, along with their respective owner. By default, objects are owned by the schema owner, however objects can have their ownership changed to any database principal.
To show how this works, I've setup a quick MCVE:
The results:
Attempt to drop the user results in an error:
If we drop the table first, then the user, the operation succeeds: