The method of SQL server backup database stored procedure

Time:2020-10-29

SQL Server batch export stored procedures

In the query analyzer, select database, right-click task, and select generate script from the pop-up menu

——》”Next step” — “select the database where you want to store the procedure”

“Next step” — check “stored procedure” and “next step”

Check the name of the stored procedure you want to generate, and then go to the next step

Select to save the script to a file, and select the save path

Another method is directly implemented by SQL statements


set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
 
 
ALTER PROCEDURE [dbo].[dbBak]  
 
AS 
BEGIN 
  DECLARE @sqlCommand NVARCHAR(1000) 
  DECLARE @dateTime NVARCHAR(20) 
  SELECT @dateTime = REPLACE(CONVERT(VARCHAR, GETDATE(),111),'/','') + 
  REPLACE(CONVERT(VARCHAR, GETDATE(),108),':','')  
  SET @sqlCommand = 'BACKUP DATABASE BLNBusyData TO DISK = ''D:\DataBaseBakUp\bln_' + @dateTime + '.BAK''' 
  EXECUTE sp_executesql @sqlCommand
END