﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 7,2000 / T-SQL  / Adding variables to Restore script / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sun, 19 May 2013 06:01:11 GMT</lastBuildDate><ttl>20</ttl><item><title>Adding variables to Restore script</title><link>http://www.sqlservercentral.com/Forums/Topic1410152-8-1.aspx</link><description>Hi all, I just need to automate a script as far as possible, at the moment I'm using Ctrl H to replace the database name and .bak with the current value, but I'd like to just pass in a couple of params at the start, and just run.  Hopefully I'll be able to create a sproc and do the same.  Here's what I've got so far, I need to keep the 'DCM' string and add on the db name from the variable...Exec master..xp_cmdshell 'MKDIR "U:\Archives\YourDatabaseNameHere\DATA"'Restore Database YourDatabaseNameHereFromDisk = 'YourBackupFilePathHere\YourDatabaseNameHere.BAK'WITH 	MOVE 'DCMYourDatabaseNameHere'		TO 'U:\Archives\YourDatabaseNameHere\DATA\YourDatabaseNameHere.mdf',        MOVE 'DCMYourDatabaseNameHere_log'	TO 'W:\Archives\Log\YourDatabaseNameHere_log.ldf',	STATS = 1 Exec master..xp_cmdshell ' DEL /Q YourBackupFilePathHere\YourDatabaseNameHere.BAK'Thanks,BLL.</description><pubDate>Tue, 22 Jan 2013 10:24:10 GMT</pubDate><dc:creator>blacklabellover2003</dc:creator></item></channel></rss>