请教:我想根据一个标准数据库复制200个数据库,要求在visual studio中完成,本来是想先复制标准数据库,然后新建目标数据库,然后恢复标准数据库上去,可是行不通。sql语句如下:
backup database sample to disk='d:\data\backup\sample.bak' with init
CREATE DATABASE data1
RESTORE FILELISTONLY
from disk='d:\data\backup\sample.bak'
restore database
data1 from
disk='d:\data\backup\sample.bak' with NORECOVERY,
move 'sample' to 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\data1.mdf',
move 'sample_log' to 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\data1_log.ldf'提示:
Server: Msg 3234, Level 16, State 2, Line 1
Logical file 'sample' is not part of database 'data1'. Use RESTORE FILELISTONLY to list the logical file names.
Server: Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
backup database sample to disk='d:\data\backup\sample.bak' with init
CREATE DATABASE data1
RESTORE FILELISTONLY
from disk='d:\data\backup\sample.bak'
restore database
data1 from
disk='d:\data\backup\sample.bak' with NORECOVERY,
move 'sample' to 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\data1.mdf',
move 'sample_log' to 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\data1_log.ldf'提示:
Server: Msg 3234, Level 16, State 2, Line 1
Logical file 'sample' is not part of database 'data1'. Use RESTORE FILELISTONLY to list the logical file names.
Server: Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
Logical file 'sample' is not part of database 'data1'
data1 from
disk='d:\data\backup\sample.bak' with NORECOVERY,
move 'sample' to 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\data1.mdf',
move 'sample_log' to 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\data1_log.ldf'
data1 from
disk='d:\data\backup\sample.bak' with NORECOVERY,
with move 'sample' to 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\data1.mdf',
move 'sample_log' to 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\data1_log.ldf'
TO DISK = 'c:\Northwind.bak'
RESTORE FILELISTONLY
FROM DISK = 'c:\Northwind.bak'
RESTORE DATABASE TestDB
FROM DISK = 'c:\Northwind.bak'
WITH MOVE 'Northwind' TO 'c:\test\testdb.mdf',
MOVE 'Northwind_log' TO 'c:\test\testdb.ldf'
GO
参考
Exclusive access could not be obtained because the database is in use.
Server: Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.