Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save LiCongMingDeShujuku/179503efe0cc1639201fc862aca5ba35 to your computer and use it in GitHub Desktop.
Save LiCongMingDeShujuku/179503efe0cc1639201fc862aca5ba35 to your computer and use it in GitHub Desktop.
Backup All Databases To Share Location With SQL
use master;
set nocount on
declare @backup_all_databases varchar(max)
set @backup_all_databases = ''
select @backup_all_databases = @backup_all_databases +
'backup database [' + name + '] to disk = ''\\MyShareName\' + replace(name, '', '''') + '.bak'' with format;' + char(10)
from sys.databases where name not in ('tempdb')
order by name asc
exec (@backup_all_databases)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment