Managing role memberships
Published 20 August 2018
Post-Deployment script to add an environment specific role member
- IF @@SERVERNAME = 'test-server'
- BEGIN
- DECLARE @return_status int
- EXEC @return_status = sp_addrolemember 'db_owner', 'a.tester'
- IF @return_status <> 0 SET NOEXEC ON
- END
- GO
Notable points:
- Post-Deployment scripts must be re-runnable as they will be executed as part of every deployment.
- Post-Deployment scripts are deployed to every environment.
@@SERVERNAME
is used to only grant a role membership toa.tester
on thetest-server
server.
- By default there is no error handling, so this script tests for an error, and sets
NOEXEC
toON
if an error occurs.