dbTalk Databases Forums  

Time to shrink a database

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Time to shrink a database in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: Time to shrink a database - 04-18-2006 , 04:07 PM






pb648174 (google (AT) webpaul (DOT) net) writes:
Quote:
The total database size is less than half a gig. Most of the time the
data is being read, with maybe 20% of the time being inserts and
updates. I would like an expert to give me the link so I know I'm not
getting the wrong thing.. I see plenty of stuff out there but am unsure
what the right thing to do is. I was hoping there would be
functionality in SQL 2005 that would just handle it.
If the database is that small, I would set up job that just loops
sysobjects and reindex every table in sight. It's not worth the effort
to anything more sophisticated.

The reason that we exempt some tables is from reindexing is mainly to
reduce execution time for the job.



--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
  #12  
Old   
pb648174
 
Posts: n/a

Default Re: Time to shrink a database - 04-20-2006 , 01:11 PM






Ok, does running the below once per week seem reasonable for a SQL 2005
DB?

DECLARE @TableName varchar(255)

DECLARE TableCursor CURSOR FOR
SELECT top 1 table_name FROM information_schema.tables
WHERE table_type = 'base table'
OPEN TableCursor

FETCH NEXT FROM TableCursor INTO @TableName
WHILE @@FETCH_STATUS = 0
BEGIN
Exec('ALTER INDEX ALL ON ' + @TableName + ' REBUILD WITH (FILLFACTOR =
80)')
FETCH NEXT FROM TableCursor INTO @TableName
END

CLOSE TableCursor

DEALLOCATE TableCursor

DBCC CHECKDB
go


Reply With Quote
  #13  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: Time to shrink a database - 04-20-2006 , 04:01 PM



pb648174 (google (AT) webpaul (DOT) net) writes:
Quote:
Ok, does running the below once per week seem reasonable for a SQL 2005
DB?
Some small modifications:

Quote:
DECLARE TableCursor CURSOR FOR
SELECT top 1 table_name FROM information_schema.tables
1) The TOP 1 should probably not be there.

2) Change "table_name" to quotename(table_name), so you can defrag
Northwind and its Order Details too. :-)

3) And change to correct case, in case you one day want to run it on
case-sensitive database. It's INFORMATION_SCHEMA etc.

And I will have to admit that I have not really digested the new
ALTER INDEX syntax in SQL 2005, but I guess that part looks find.


--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.