This is a SQL Express install so there is no Agent listed, so I can't create a job.
When I run the SQL script below either in the batch file or at sqlcmd prompt it just opens the .sql file in SSMS and does not run it. I want this to run unattended at night. What do I need to do to make this work?
Shown below are my two files: the first is my sql script, second is the command prompt
The SQL script creates a backup file just fine when I run it manually in SSMS, however the purpose of this is unattended.
Or any other suggestions would be great
TIA
When I run the SQL script below either in the batch file or at sqlcmd prompt it just opens the .sql file in SSMS and does not run it. I want this to run unattended at night. What do I need to do to make this work?
Shown below are my two files: the first is my sql script, second is the command prompt
The SQL script creates a backup file just fine when I run it manually in SSMS, however the purpose of this is unattended.
Or any other suggestions would be great
TIA
Code:
-- get todays date
Declare @TodaysDate as nvarchar(10) = Replace(CONVERT(nvarchar(10), getdate(), 103),'/', '')
Declare @FileName as nvarchar(100) = N'D:\SQLBackup\StockTrack_' + @TodaysDate + '.bak'
BACKUP DATABASE [StockTrack] TO DISK = @FileName
WITH NOFORMAT,
NOINIT, NAME = N'StockTrack-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO
Code:
sqlcmd -S ServerName\SQLExpress -i C:\mybackup.sql