Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

SQL SERVER database backup code example

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article is an example to share the specific code of SQL SERVER database backup for your reference, the specific contents are as follows

/ * * batch cyclic backup of user database Temporary use of * / SET NOCOUNT ONDECLARE @ d varchar (8) DECLARE @ Backup_Flag NVARCHAR (10) SET @ d=convert (varchar (8), getdate (), 112) / * customize which databases to back up * /-- SET @ Backup_Flag='UserDB'-- user database SET @ Backup_Flag='AlwaysOnDB'-- AlwaysOn user database CREATE TABLE # T (ID INT NOT NULL IDENTITY (1)) SQLBak NVARCHAR (MAX) NOT NULL) IF @ Backup_Flag='UserDB'BEGIN INSERT INTO # T (SQLBak) SELECT 'BACKUP DATABASE [' + name +'] TO DISK=''E:\ Backup\'+ NAME +'_ Full_'+@d+'.bak'' WITH CHECKSUM,NOFORMAT,INIT,SKIP COMPRESSION' AS 'SQLBak' FROM sys.databases WHERE database_id > 4ENDIF @ Backup_Flag='AlwaysOnDB' BEGIN INSERT INTO # T (SQLBak) SELECT' BACKUP DATABASE ['+ database_name +'] TO DISK=''E:\ Backup\'+ database_name +'_ Full_'+@d+'.bak'' WITH CHECKSUM,NOFORMAT,INIT,SKIP,COMPRESSION' AS 'SQLBak' FROM sys.availability_databases_clusterENDDECLARE @ Minid INT, @ Maxid INT, @ sql VARCHAR (max) SELECT @ Minid = MIN (id) @ Maxid = MAX (id) FROM # TPRINT Noble color-print backup script. 'WHILE @ Minid

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report