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.
@@SERVERNAMEis used to only grant a role membership toa.testeron thetest-serverserver.
- By default there is no error handling, so this script tests for an error, and sets
NOEXECtoONif an error occurs.
This documentation contains proprietary information and is protected by copyright law.
Copyright © 2026 Red Gate Software Limited. All rights reserved