Home  |  About  | Last |  Submit  |  Contact
AllQuests.com

Previous Question:  Difficulty Theming AJAX Tab Control  AJAXNext Question:  Tiger Woods Question  Xbox 360 Games
Question Restore with new name ( CodeGuru Forums Database )
Updated: 2008-08-12 06:08:48 (1)
Restore with new name

Hello

I'd like to make a copy of database with new name. The name must be set in the run time. I mean
data: 2008/MM/DD it means that the name should be set test_2008
data: 2009/MM/DD it means that the name should be set test_2009
and so on ...

I have prepared sql batch file as follows.

Code:
[1]USE ABBMeasureHistory [2]GO [1]DECLARE @y varchar(10) [2]SET @y = SUBSTRING(CONVERT(char, GETDATE(), 102),0,5) [3]SELECT @y [4]RESTORE FILELISTONLY [5] FROM DISK = 'c:\sql\ABBMeasureHistory.bak'; [6]RESTORE DATABASE 'ABBMeasureHistory_' + @y [7] FROM DISK = 'c:\sql\ABBMeasureHistory.bak' [8] WITH RECOVERY, [9] MOVE 'ABBMeasureHistory_dat' TO 'c:\Program Files\Microsoft SQL Server\MSSQL\Data\ABBMeasureHistory_' + @y + '.mdf', [10] MOVE 'ABBMeasureHistory_log' TO 'c:\Program Files\Microsoft SQL Server\MSSQL\Data\ABBMeasureHistory_' + @y + 'Log.ldf' [11]GO


Unfortnately ther is a bug. The system returns a fault message as follows:
1> 2> 1> 2> 3> 4> 5> 6> 7> 8> 9> 10> 11> Msg 170, Level 15, State 1, server TEST, Line 6
Line 6: Incorrect syntax near 'ABBMeasureHistory_'.
1>


Could you please help me to solve this issue

Thanks i nadvance


Andrzej

Answers: Restore with new name ( CodeGuru Forums Database )
Restore with new name

I've just found a bug

it is not allowed to asign variable as follows
Code:
... @v = 'test' + @y ...

insted of this it should be
Code:
... SET @v = 'test' + @y ...

Andrzej

Previous Question:  Difficulty Theming AJAX Tab Control  CodeGuru Forums  AJAXNext Question:  Tiger Woods Question  AVForums  Xbox 360 Games

- Source: Restore with new name CodeGuru Forums Database
- Previous Question: Difficulty Theming AJAX Tab Control CodeGuru Forums AJAX
- Next Question: Tiger Woods Question AVForums Xbox 360 Games





AllQuests.com


Best dedicated servers   Top dedicated servers   Cheap dedicated servers   Linux dedicated servers   Windows dedicated servers   Unmetered dedicated servers