Solved

SQL Server 2000 Rename DB with illegal character

Posted on 2003-11-10
2
726 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction: Often, when running a query with joins, the results show up "duplicates", and often, those duplicates can be "eliminated" in the results using DISTINCT, for example. Using DISTINCT is simple: just add it after the SELECT keyword, an…
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
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…

707 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

16 Experts available now in Live!

Get 1:1 Help Now