asked on
use DB_Production;
--Remove User from production DB about to be swapped out
exec sp_dropuser 'MyUser';
--Set to single user to close all open connections
ALTER DATABASE DB_Production SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
ALTER DATABASE DB_Production SET MULTI_USER WITH ROLLBACK IMMEDIATE;
--Rename
exec SP_RENAMEDB 'DB_Production','DB_TMP';
--Set to single user to close all open connections
ALTER DATABASE DB_Production_staging SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
ALTER DATABASE DB_Production_staging SET MULTI_USER WITH ROLLBACK IMMEDIATE;
--Rename
exec SP_RENAMEDB 'DB_Staging','DB_Production's;
exec SP_RENAMEDB 'DB_TMP','DB_Staging';
use DB_Production;
--Add User to newly swapped production DB
exec sp_adduser 'MyUser';