DECLARE @cmd nvarchar(255);
SET @cmd = 'IF ''?'' NOT IN(''master'', ''model'', ''msdb'', ''tempdb'')
BEGIN USE ? exec sp_changedbowner sa END';
EXEC master.sys.sp_MSforeachdb @command1 = @cmd
This is my collection of mostly useful SQL server information that helps administer the server. It is mostly aimed at SQL Server 2012 / 2014 / 2016.
Final screen shot of the role allowing access but locking the user out of changes and the definition |