Microsoft Knowledge Base Email Alertz

KBAlertz.com: In SQL Server 2000, you can add, delete, and rename the data files and the transaction log files. This article explains how to consolidate physical files, and how to rename the logical file name in SQL Server 2000.

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 814576 - Last Review: May 11, 2007 - Revision: 4.4

How to consolidate physical files and rename the logical file name in SQL Server 2000 and in SQL Server 2005

On This Page

SUMMARY

In Microsoft SQL Server 2000 and in MicrosoftSQL Server 2005, you can add, delete, and rename the data files and the transaction log files. This article explains how to consolidate physical files, and how to rename the logical file name in SQL Server 2000 and in SQL Server 2005.

MORE INFORMATION


Consolidate Physical Files

You may have to consolidate files or reduce the number of physical files for a server that is running SQL Server 2000 or SQL Server 2005. To reduce the number of physical files, you can delete the files. To consolidate the files, you can purge inactive transactions.

Deleting Files

Deleting a data or a transaction log file removes the file from the database. However, you cannot remove a file from a database if the file contains data or transaction log information. You can only remove a file if the file is empty. If you have data that you want to keep, you can migrate the data from a data file to other files in the same filegroup. To migrate the data, you can use a DBCC SHRINKFILE statement and specify the EMPTYFILE clause. Then, SQL Server no longer allows data to be inserted in the file, and you can delete the file by using an ALTER DATABASE statement.

You cannot migrate the transaction log data from one log file to another to delete a transaction log file.

Purging Inactive Transactions

To purge inactive transactions from a transaction log file, you must truncate or back up the transaction log. When a transaction log file no longer contains any active or inactive transactions, you can remove the log file from the database. To remove the log file from the database, use these steps:
  • To shrink data or information in a file and to make the file empty, run the following Transact-SQL statement:
    DBCC SHRINKFILE ('<logical file name>', EMPTYFILE ) 
  • To delete a file from a database, run the following Transact-SQL statement:
    ALTER DATABASE <Database name>  REMOVE FILE <logical file name> 
    

IMPORTANT After you add or delete files, create a database backup immediately. You must create a full database backup before you create a transaction log backup.

Rename Logical File Name

To modify the logical name of a data file or a log file, specify the logical file name you want to rename by using the Name parameter, and then specify the new logical name for the file by using the NewName parameter. To rename the logical file, run the following Transact-SQL statement:
ALTER DATABASE <Database name>  MODIFY FILE  ( NAME = <current_logical_name>, NEWNAME = <new_logical_name>)

REFERENCES

For more information, visit the following Microsoft Web sites:

Adding and Deleting Data and Transaction Log Files (http://msdn2.microsoft.com/en-us/library/aa933089(SQL.80).aspx)

DBCC SHRINKFILE (http://msdn2.microsoft.com/en-us/library/aa258824(SQL.80).aspx)

Physical Database Files and Filegroups (http://msdn2.microsoft.com/en-us/library/aa174545(SQL.80).aspx)

ALTER DATABASE (http://msdn2.microsoft.com/en-us/library/aa275464(SQL.80).aspx)

Expanding a Database (http://msdn2.microsoft.com/en-us/library/aa933083(SQL.80).aspx)

Shrinking a Database (http://msdn2.microsoft.com/en-us/library/aa933076(SQL.80).aspx)

For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
324432  (http://kbalertz.com/Feedback.aspx?kbNumber=324432/EN-US/ ) PRB: DBCC SHRINKFILE and SHRINKDATABASE Commands May Not Work Because of Sparsely Populated Text, Ntext, or Image Columns

APPLIES TO
  • Microsoft SQL Server 2000 Standard Edition
  • Microsoft SQL Server 2005 Developer Edition
  • Microsoft SQL Server 2005 Enterprise Edition
  • Microsoft SQL Server 2005 Express Edition
  • Microsoft SQL Server 2005 Standard Edition
  • Microsoft SQL Server 2005 Workgroup Edition
Keywords: 
kbsysadmin kbinfo kbhowto kbfaq KB814576
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please