Reputation: 1787
I have a MSSQL Database named "Database". Now when I am trying to rename it using query shown below,
USE master;
GO
ALTER DATABASE Database
Modify Name = Database01
GO
It gives me this error message:
Msg 102, Level 15, State 1, Line 1 Incorrect syntax near 'Database'.
But this query works fine for other database. What I am doing wrong?
Upvotes: 2
Views: 746
Reputation: 1620
Instead of using the the Long code you Can just use the System built-in Stored Procedure -sp_renamedb'oldDBName','NewDBName'
Upvotes: 1
Reputation: 592
when you have to use reserved keywords for table name,database name,column name always put [] (big brackets )
such as
select * from [Table]
in place of select * from table
select [column] from [table]
in place of select column from table
but its very bad idea to put reserved keyword as a name for your objects.
Upvotes: 0
Reputation: 2112
If you "quote" the table name it should work. The default quote characters are square brackets [], so:
USE master;
GO
ALTER DATABASE [Database]
Modify Name = Database01
GO
Upvotes: 7