*********************************************************
** Author Subramanian.G
** Function to rebuild CDX index ... this does....
** First deletes the index and then recreates them
** How to ... =BuildIndex(myDBF)
** Last Modified : 19 November, 2004
*********************************************************
FUNCTION BuildIndex
PARAMETERS myDBF
IF PARAMETERS() # 1
RETURN .F.
ENDIF
LOCAL laIndex, cKey, cIndex
USE (myDBF)
DIMENSION laIndex(254,3)
*** Load the index name and key names in array
FOR nCount = 1 TO 254
IF !EMPTY(TAG(nCount)) && Checks for tags in the index
laIndex(nCount,1) = TAG(nCount) + ' ' && tag name
laIndex(nCount,2) = KEY(nCount) + ' ' && Key name
IF PRIMARY(nCount) && Check Index type
laIndex(nCount,3) = 'P' && Primary Index
ELSE
IF CANDIDATE(nCount)
laIndex(nCount,3) = 'C' && Candidate Index
ELSE
laIndex(nCount,3) = 'O' && Other Index types
ENDIF
ENDIF
ELSE
EXIT && Exit the loop when no more tags are found
ENDIF
ENDFOR
*** Delete the tags
DELETE TAG ALL
*** Rebuild Index
FOR nCount = 1 TO 254
IF !EMPTY(laIndex(nCount,1))
cIndex = ALLT(laIndex(nCount,1))
cKey = ALLT(laIndex(nCount,2))
IF laIndex(nCount,3) = 'P'
** Create Primary key type
ALTER TABLE (myDBF) ADD PRIMARY KEY &ckey ;
TAG &cindex
ELSE
IF laIndex(nCount,3)='C'
&& Candidate index
INDEX ON &cKey TAG &cIndex candidate
ELSE
INDEX ON &cKey TAG &cIndex
ENDIF
ENDIF
ELSE
EXIT && Exit the loop when no more tags are found
ENDIF
ENDFOR
USE
RETURN .T.
*********************************************************
** EOF
*********************************************************
** You can cut & paste and use the above function.
** Remember to backup & test this before/after execution.
** Accept it at your own risk.
********************************************************
Hope this helps users
Ramani
FoxAcc Software
(ramani_g@yahoo.com)
Subramanian.G
www.winnersoft.coolfreepages.com
********************************************************
Evaluate this to make others know how useful is this
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.