You are on page 1of 2

SAP Business One Notes

1241422 - Database defragmentation and reindexing improves performance


Version 8 Validity: 07.07.2014 - active

Language English

Symptom
During the lifetime of anSAP Business Onedatabase, due to insertions, updates. and deletions of
data, the information in indexes become fragmented.Fragmentation exists when indexes have pages in
which the logical ordering, based on the key value, does not match the physical ordering inside the
data file. Heavily fragmented indexes can degrade performance.

Reproducing the issue


Prerequisites:
You are usingSAP Business One.
Scenario:
Data operations in the SAP Business One database result fromthe use of the application.
Expected behavior:
Information in indexes is notfragmented.
Actual behavior:
Information in indexes is fragmented.

Cause
Consulting

Solution
Werecommend runningthefollowing rebuilding procedure once or twice a month:
/*
Reindex procedure.
Will execute dbcc dbreindex on each table in db
*/

DECLARE @tableName as sysname


DECLARE @strExec as varchar(1000)
-- Cursor declartion
DECLARE tableNameCursor CURSOR READ_ONLY FAST_FORWARDFOR
-- Take all user table
SELECT [name] FROM sysobjects WHERE xtype = 'U'
OPEN tableNameCursor
FETCH NEXT FROM tableNameCursor INTO @tableName
WHILE @@FETCH_STATUS = 0
BEGIN
-- Create the statment
SET @strExec = 'dbcc dbreindex (''' + @tableName + ''','''',0 )'
-- Execute the procedure
exec (@strExec)

FETCH NEXT FROM tableNameCursor INTO @tableName


END
CLOSE tableNameCursor
DEALLOCATE tableNameCursor
Before running:
Be sure you have enough free space (up to twice the size of used space).
If you need to shrink the database (it is not recommended - it will create fragmentation), do it
before the re-index. You can use the following script:
/*-----------------------------------------------------------------------Shrink db
--------------------------------------------------------------------------*/

DECLARE @dbName as sysname


DECLARE @strExecShrink as varchar(500)
-- Get db name
SET @dbName = (select db_name())
SET @strExecShrink = 'DBCC SHRINKDATABASE(''' + @dbName + ''',10)'
EXEC(@strExecShrink)
The re-index takes a while (it may run more than two hours on a large database); during this
operation, the database will not be available for use.
Related resources:
SQL ServerBooks Online.
http://msdn.microsoft.com/en-us/library/ms189858(SQL.90).aspx.

Other terms
Index, performance, re-index, reindex, slow, poor, DB, SAP Business One , defrag, database

Header Data
Released On
Release Status
Component

07.07.2014 09:16:20
Released for Customer
SBO-BC-PER Performance

Other Components SBO-BC System


SBO-SH-SYS-A3 Performance
Priority
Category
Database

Recommendations/additional info
Consulting
MicrosoftSQL Server 2005
MicrosoftSQL Server 2008
MicrosoftSQL Server 2012

Validity
Software Component Version
SAP BUSINESS ONE 2005 A SP01
2005 B
2007 A
2007 B
8.8
8.81
8.82
9.0
9.1

References
This document refers to:
SAP Business One Notes
1376447 Support scope for SAP Business One database index creation
783183 Slow performance in SAP Business One or SQL query

This document is referenced by:


SAP Business One Notes (2)
1567174 Slow performance after upgrade to SAP Business One 8.8
1564494 Perfomance problem when running SAP Add-ons

You might also like