• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 442
  • Last Modified:

Sysfiles name shows wrong database

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
evcevis
Asked:
evcevis
1 Solution
 
MikeWalshCommented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now