Solved

SQL Server 2000 Rename DB with illegal character

Posted on 2003-11-10
2
727 Views
Last Modified: 2012-08-14
Need an answer fast to this question.

I created a database with a - ("dash") in the name. The ultimate sin! If its such a sin it should not allow you to create it. You get no error when you create it which is really stupid if you ask me.

Help!! Please!! I need to rename the database I want to change the - to an _ which I think is legal. Any ideas on how? I tried ALTER DATABASE MODIFY NAME= , but it gives me an error "error near -". SQL Server 2000. I even tired a proc, but it got the same error. Has anyone ever done this before???

Doug
0
Comment
Question by:DougC
2 Comments
 
LVL 3

Accepted Solution

by:
syntnx earned 60 total points
ID: 9716850
Try this procedure. I had it bookmarked from the following http://databasejournal.com/features/mssql/article.php/1440501

CREATE PROCEDURE usp_RenameDB
    @OldDatabaseName varchar(50),
    @NewDatabaseName varchar(50)
WITH ENCRYPTION
AS
BEGIN
    DECLARE @OldTranCount  INTEGER;

    SET @OldTranCount = @@TRANCOUNT;

    WHILE (@@TRANCOUNT > 0)
        ROLLBACK TRANSACTION

    EXEC sp_dboption @OldDatabaseName, 'single user', 'TRUE'
    EXEC sp_renamedb @OldDatabaseName, @NewDatabaseName
    EXEC sp_dboption @NewDatabaseName, 'single user', 'FALSE'

    WHILE (@@TRANCOUNT < @OldTranCount)
        BEGIN TRANSACTION
END
GO

syntnx
0
 

Expert Comment

by:WinstonRaja
ID: 9721227
Hi

Alternatively you can use [ ]  brace to overcome these errors
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now