Backtrack:  
 
by lunarg on March 8th 2011, at 10:24

It's possible to rename the logical names of MS-SQL databases through the SQL-prompt (osql.exe).

Log in to your database using osql:

> osql -S SERVERINSTANCE -d MyDB -U sa

First, query the current logical names; you will need them in order to rename them.

1> SELECT * FROM sysfiles
2> GO

fileid	groupid	size	maxsize	growth	status	perf	name	filename
1	1	106224	-1	10	1048578	0	OldName_Data	D:\SQL2000\Data\MyDB_Data.mdf
2	0	128	-1	10	1048642	0	OldName_Log	D:\SQL2000\Data\MyDB_Log.ldf

The name column specifies the logical names. Use the following SQL statement to rename them.

1> ALTER DATABASE [MyDB] MODIFY FILE (NAME = 'OldName_Data', NEWNAME = 'NewName_Data')
2> ALTER DATABASE [MyDB] MODIFY FILE (NAME = 'OldName_Log', NEWNAME = 'NewName_Log')
3> GO

You can rename both the data files and log files. If the rename was succesful, a message will tell you so.

 
 
« December 2024»
SunMonTueWedThuFriSat
1234567
891011121314
15161718192021
22232425262728
293031    
 
Links
 
Quote
« Debating Windows vs. Linux vs. Mac is pointless: they all have their merits and flaws, and it ultimately comes to down to personal preference. »
Me