Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Sqlserver Backup
Message
 
À
18/10/2019 00:55:50
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01671546
Message ID:
01671549
Vues:
64
>Sir I have these codes
>
>
>
>DECLARE @name VARCHAR(50) -- database name  
>DECLARE @path VARCHAR(256) -- path for backup files  
>DECLARE @fileName VARCHAR(256) -- filename for backup  
>DECLARE @fileDate VARCHAR(20) -- used for file name
> 
>-- specify database backup directory
>SET @path = 'C:\Backup\'  
> 
>-- specify filename format
>SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) 
> 
>DECLARE db_cursor CURSOR READ_ONLY FOR  
>SELECT name 
>FROM master.sys.databases 
>WHERE name NOT IN ('master','model','msdb','tempdb')  -- exclude these databases
>AND state = 0 -- database is online
>AND is_in_standby = 0 -- database is not read only for log shipping
> 
>OPEN db_cursor   
>FETCH NEXT FROM db_cursor INTO @name   
> 
>WHILE @@FETCH_STATUS = 0   
>BEGIN   
>   SET @fileName = @path + @name + '_' + @fileDate + '.BAK'  
>   BACKUP DATABASE @name TO DISK = @fileName  
> 
>   FETCH NEXT FROM db_cursor INTO @name   
>END   
>
> 
>CLOSE db_cursor   
>DEALLOCATE db_cursor
>
>
>Ref: https://www.mssqltips.com/sqlservertip/1070/simple-script-to-backup-all-sql-server-databases/
>
>I put these codes into new query and click Execute.
>The codes work fine.
>
>Now I want these codes automatically run at 11PM every night.
>
>What should I do?
>
>Should I create a Stored procedure,
>if yes then how it will be execute automatically at scheduled time?
>
>Or is there any other possibility.
>
>Please help

If you use Express version of SQL Server and have no way to use SQL Agent, then save this code in pure text file with SQL extension and use Windows scheduler to execute SQLCMD command prompt utility.
https://docs.microsoft.com/en-us/sql/ssms/scripting/sqlcmd-run-transact-sql-script-files?view=sql-server-ver15
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform