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 PROCEDUREon it's own won't allow you to create a procedure. In fact, giving aROLEtheCREATE PROCEDUREpermission, and notALTERon the schema will result in the below error:There is no
ALTER PROCEDUREpermissions, therefore, for a member of aROLEto be able to bothCREATEandALTERaPROCEDUREyou would need to do:This, however, will also enable to user to
ALTERanyprocedures on said schema. Ut also enable those in the role toALTERother objects on the schema as well (such as tables) though.If your
ROLEhas permissions toALTERthe procedures and you want to remove that, you would need to run the below:This will, as mentioned, also revoke their ability to
ALTERany other objects on said schema.Remember,
REVOKEdoesn'tDENY, it simply means that theUSERwon't inherited that permission from thatROLEany more. If theUSERhas 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 aUSERfrom performing an action, regardless of any other permissions, they must have theDENYpermission.