Hello,
I am trying to move hundreds of databases from one server to another and trying to build a script to help along. Both servers are SQL 2000
I need to do one at a time over the next week after each database is ready. I am trying this:
The variable will work on everything except for the 'create' and 'use' databases.
I get the error: Incorrect syntax near @dbname
I thought it might have to do something with my Varchar variable type and the use of single quotes, but I have tried without quotes and it hasn't helped.
Thanks!
I am trying to move hundreds of databases from one server to another and trying to build a script to help along. Both servers are SQL 2000
I need to do one at a time over the next week after each database is ready. I am trying this:
Code:
declare @dbname varchar(100)
set @dbname = 'Batch1'
create database @dbname
restore database @dbname
from disk = '\\server\share\@dbname'
with init
use @dbname
sp_changedbowner USC
The variable will work on everything except for the 'create' and 'use' databases.
I get the error: Incorrect syntax near @dbname
I thought it might have to do something with my Varchar variable type and the use of single quotes, but I have tried without quotes and it hasn't helped.
Thanks!