肖恩D++
Not Equal C && !=C && 不等于西
-
One Script to Backup All SQL Databases
Posted on August 15th, 2011 Add commentsIt’s a nightmare for backup your DB if you have 100+ DB’s in SQL server. Just simply run a script while you taking a coffee:
12345678910111213141516171819202122232425262728DECLARE @name VARCHAR(50) -- database nameDECLARE @path VARCHAR(256) -- path for backup filesDECLARE @fileName VARCHAR(256) -- filename for backupDECLARE @fileDate VARCHAR(20) -- used for file nameSET @path = "C:\Backup"SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112)DECLARE db_cursor CURSOR FORSELECT nameFROM master.dbo.sysdatabasesWHERE name NOT IN ('master','model','msdb','tempdb')--skip system database (optional)OPEN db_cursorFETCH NEXT FROM db_cursor INTO @nameWHILE @@FETCH_STATUS = 0BEGINSET @fileName = @path + @name + '_' + @fileDate + '.BAK'BACKUP DATABASE @name TO DISK = @fileNameFETCH NEXT FROM db_cursor INTO @nameENDCLOSE db_cursorDEALLOCATE db_cursor
Leave a Reply
Be the First to Comment!