DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
 
 
SITE SEARCH SQLUSA.com VIDEOS
 
 
SQL E/BOOKS   WORLD, USA & SQL NEWS   FORMAT
SCRIPTS SQL 2005 SQL 2008 ARTICLES
How to restore a database from a batch?

Execute the following Microsoft SQL Server T-SQL batch script in SSMS Query Editor to restore the AdventureWorks database from a backup file using the SQLCMD command line utility:

-- Basic RESTORE DB syntax with overwrite current

RESTORE DATABASE [Alpha] FROM  DISK = N'F:\backup\AW8.BAK' WITH  FILE = 8,

NOUNLOAD, REPLACE,  STATS = 10

GO

------------

-- RESTORE DATABASE to a new location syntax

RESTORE DATABASE [NEWAdventureWorks] FROM  DISK = N'F:\temp\AW.bak'

WITH  -- FILE = 6, 

MOVE N'AdventureWorks_Data' TO N'F:\data\AW.mdf', 

MOVE N'AdventureWorks_Log' TO N'F:\data\log\AW8.ldf', 

NOUNLOAD,  STATS = 10

GO

------------

USE master
DECLARE @RestoreStatement nvarchar(256)
DECLARE @BackupFile nvarchar(50)
DECLARE @CommandText nvarchar(512)
DECLARE @SQLCMD nvarchar(50)

SET @BackupFile = '''d:\data\backup\AdventureWorks.bak'''
SET @SQLCMD = 'SQLCMD -SServerName -E -Q '
SET @RestoreStatement = 'USE MASTER ALTER DATABASE AdventureWorks SET SINGLE_USER WITH ROLLBACK IMMEDIATE; RESTORE DATABASE AdventureWorks FROM DISK='
SET @CommandText = @SQLCMD + '"' + @RestoreStatement + @BackupFile +'"'
PRINT @CommandText
EXEC master.dbo.XP_CMDSHELL @CommandText

 

Exam Prep 70-461
SQL 2016 DESIGN & PROGRAMMING
 
 
 
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE