Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ReBuild your CDX index files

Databases and tables

ReBuild your CDX index files

by  ramani  Posted    (Edited  )
*********************************************************
** 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 :)
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top