Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
craigwg
Posting Yak Master
154 Posts |
Posted - 2009-07-31 : 09:55:15
|
| Hi,I have a server that is getting low on space. Its a test server so there is a lot of junk and remnants spread out. I am looking for ideas on cleaning duplicate mdf and ldf files. For example MDF/LDF files that are not linked to active databases. I'd love to delete those. Any links or thoughts would be magnificent!Craig GreenwoodCraig Greenwood |
|
|
craigwg
Posting Yak Master
154 Posts |
Posted - 2009-07-31 : 11:55:58
|
| For the record I found this query useful. You have to play with the where statement in the second query to dictate the drives you want to look at. Highly recommended:[code]use mastercreate table #temp(dbname varchar (200) NULL,name varchar (200),fileid int,location varchar (250),filegroup varchar (15),size varchar (20),maxsize varchar (20),growth varchar (20),usage varchar (20))declare @dbname sysnamedeclare @cmd nvarchar(300)declare c cursor for select name from master.dbo.sysdatabases where status < 499 or status > 599 open cfetch next from c into @dbnamewhile @@fetch_status = 0begin select @cmd = N'use ' + quotename(@dbname) + N' INSERT INTO #TEMP (name, fileid, location, filegroup, size , maxsize , growth, usage) exec sp_helpfile ' exec (@cmd) UPDATE #TEMP SET DBNAME = @DBNAME WHERE DBNAME IS NULLfetch next from c into @dbnameendclose cdeallocate c SELECT dbname, name, filegroup, location FROM #TEMP WHERE usage like '%data%' and location not like 'G:%' or usage like '%log%' and location not like 'I:%' order by dbname, nameDROP TABLE #TEMP[\code]Craig Greenwood |
 |
|
|
|
|
|
|
|