Solved

Sysfiles name shows wrong database

Posted on 2008-06-19
1
429 Views
Last Modified: 2008-06-19
I've inherited a database that had relatively large log files. Datafiles: 23GB, 11GB, 9GB. Log files: 25GB, 13GB, 10GB. I wanted to get this fixed. I backed up the databases and then tried to run DBCC Shrinkfile. On database1 and 3 I had no problems. But on database2, it fails with "could not locate file 'database2' in sysfiles. I looked at sysfiles for database2 and the filename column points to database2.mdf and database2_log.ldf. However, the name column shows database1_dat and database1_log.

Will ALTER DATABASE resolve this?
0
Comment
Question by:evcevis
1 Comment
 
LVL 13

Accepted Solution

by:
MikeWalsh earned 250 total points
ID: 21827910
My guess here is that the logical/physical names got screwed up during a restore operation previously.

So you should be able to use Alter Database to modify your logical filename.

From BOL:

ALTER DATABASE test
MODIFY FILE
    (NAME = oldname, NEWNAME = newname);
GO

If you have an issue with the physical name you would just use the move command for that logical file and put the new path/name for the new physical name.


I know you didn't ask this, but I also would comment on the practice of shrinking files. It is generally a bad practice. Files grew to their size for a reason. If you go through the process of shrinking a file and it grows back you now have a performance hit during that growth and you are causing potential fragmentation and data access perf hits moving forward. When you shrink a log file and allow it to grow, that log file will now have more virtual log files which can also cause a performance hit.

I generally like to grow the files to the size I expect them to be for the next n months and set them once. Just food for thought. Paul Randal, formerly of the SQL Server Storage Engine team at Microsoft, blogs about this on his blog: http://www.sqlskills.com/blogs/paul/
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

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

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

13 Experts available now in Live!

Get 1:1 Help Now