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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Indexes Explained?

Status
Not open for further replies.

dcomartin

Programmer
May 12, 2003
27
0
0
CA
Alright, the only thing that I think is still puzzling me with dBase are indexes. So here is my question. In the code im dealing with, I often see this:

----
USE someTable INDEX someIndex1, someIndex2, someIndex3
----

My understanding of indexes (as someone pointed out to me before on this forum) is that an index contains pointers to the real table in the order that you want. So when you USE a table with multiple indexes, how does that work then?

Also, my only other question is, when you are inserting/deleting records from a table, do the indexes (im only using NDX indexes) automaticlly get updated, or is that purpose of using multiple indexes in my above example? Meaning that if you USE a table, and make changes, the only indexes taht will get updated are the indexes you opened with that table?
 
Your first question:
When you open a table with multiple indexes, only one is in effect. You can put another open index file in effect using :

SET ORDER TO x <number> (where number refers to the indexes position in the index file list in the USE <filename> INDEX command)

Or:

SET ORDER TAG <tagname> OF <filename>.MDX (this is for using other indexes (&quot;tags&quot;) in a multiple index file with extension .MDX) This isn't applicable in your instance when using only .NDX files.

Your second question:
YES. Only indexes which are open when updates/adds/deletes get made on a data table are updated. That is the reason good practice calls for always opening all the associated single index files (.NDXs) when opening a database for any updates. Not having all the index files open when making updates to a database are the most common reason for corrupted (really unsynchronized) index errors. Be aware that having lots of index files open can slow things down. This was a problem in the old days, probably not so much anymore with speed processors.

So if you have a database with the key fields name, addr, zipcode, you might deal with it thus:

USE MyTAble INDEX iname, iaddr,izipcode && default order will be by iname index
SET ORDER TO 3 && sets order to zipcode using the izipcode.ndx index file.

HTH.
Dennis

 
Thanks for the reply Dennis. It all makes sense now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top