Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL Server 2000 Rename DB with illegal character

Posted on 2003-11-10
2
Medium Priority
?
739 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 240 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

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

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

In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
How much do you know about the future of data centers? If you're like 50% of organizations, then it's probably not enough. Read on to get up to speed on this emerging field.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

927 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