I want to create three SQL Server database roles.
- That can CREATE, ALTER and EXECUTE all stored procedures in database
- That can only EXECUTE all stored procedures in database
- That have no access to any stored procedures in database
I have created the roles, but I'm facing issues while REVOKE their permissions.
I have executed
REVOKE CREATE PROCEDURE TO [ROLE NAME]
to revoke the permissions to create the procedure and it executed successfully.
But I got error while executing this statement:
Error: Incorrect syntax near 'ALTER'.
I am very new to SQL server role rights so I might be completely wrong with my approach.
Please guide me to achieve my goal in correct way.
Thanks
From the documentation Create a Stored Procedure:
Therefore just giving
CREATE PROCEDURE
on it's own won't allow you to create a procedure. In fact, giving aROLE
theCREATE PROCEDURE
permission, and notALTER
on the schema will result in the below error:There is no
ALTER PROCEDURE
permissions, therefore, for a member of aROLE
to be able to bothCREATE
andALTER
aPROCEDURE
you would need to do:This, however, will also enable to user to
ALTER
anyprocedures on said schema. Ut also enable those in the role toALTER
other objects on the schema as well (such as tables) though.If your
ROLE
has permissions toALTER
the procedures and you want to remove that, you would need to run the below:This will, as mentioned, also revoke their ability to
ALTER
any other objects on said schema.Remember,
REVOKE
doesn'tDENY
, it simply means that theUSER
won't inherited that permission from thatROLE
any more. If theUSER
has the permission from a differentROLE
, or they have the permission themselves, they will be able to continue to use the permission. If you must stop aUSER
from performing an action, regardless of any other permissions, they must have theDENY
permission.