变量名称和字符串连接'+'错误作为不正确的语法

时间:2013-10-11 06:28:19

标签: sql-server database-restore

RESTORE DATABASE Umbraco6
FROM  DISK = 'C:\Temp\initial_db.bak'
    WITH  MOVE 'Umbraco6'     TO @db_physical_path  + '\test_data.mdf',
MOVE 'Umbraco6_log' TO  @db_physical_path + '\test_data.ldf',
REPLACE

在上面的SQL脚本中我收到错误:

  

'''附近的语法错误不正确。

有什么想法吗?

1 个答案:

答案 0 :(得分:5)

declare @db_physical_path_data nvarchar(200)
declare @db_physical_path_log nvarchar(200)

set @db_physical_path_data = @db_physical_path + '\test_data.mdf'
set @db_physical_path_log = @db_physical_path +'\test_data.ldf'

RESTORE DATABASE Umbraco6
 FROM DISK = N'C:\Temp\initial_db.bak'
 WITH MOVE N'Umbraco6' TO @db_physical_path_data,
 MOVE N'Umbraco6_log' TO @db_physical_path_log, REPLACE