Say you are migrating databases from one server to another. You don’t want users connect to the old instance by mistake. You can do that by putting them all offline. Below is the script t
set nocount on
select ‘alter database ‘ + name + ‘ set offline’ from sysdatabases where
name not in (‘master’, ‘msdb’, ‘model’, ‘tempdb’)