main logo
Subject: RE: Where did 'Unique' index type go to?
Author: "Nancy Folsom"
Posted: 2004/04/30 17:11:31
 
View Entire Thread
New Search


Matthew-

> I'm not saying Unique indexes are great or anything, just
> saying that I've used them... don't recall ever using them in
> a program, but they have their uses at the command line....
>
> Or do you need to educate me about something?

Alrighty. In a nutshell, UNIQUE index tags can give you misleading results.
Woody has illustrated the single most brilliant and useful trick for UNIQUE,
but that's strictly a command line or ad hoc sort of occasion. It's been a
helluva long time since I've needed it, but it's really great if your
massaging a lot of data conversions. However, as a permanent index...like I
said...bad dog. Here's an example of how a unique index can bite you.

* Begin code
SET DELETED ON
CLEAR

* Create a sample table
CREATE TABLE UniqueEx (I1 N(1,0), C1 C(10))
INSERT INTO UniqueEx VALUES (RECCOUNT('UniqueEx'),"Goodbye")
INSERT INTO UniqueEx VALUES (RECCOUNT('UniqueEx'),"Hello")
INSERT INTO UniqueEx VALUES (RECCOUNT('UniqueEx'),"Hello")
LIST I1, C1 && We see all three records, as expected

* Create (and activate) a duplicate index
INDEX ON C1 TAG C1Unique UNIQUE
LIST I1, C1 && Two records, as expected

* Delete one of the duplicates
GO BOTTOM
DELETE
LIST I1, C1 && Just one record (neither "Hello")

* Reindexing doesn't show us the second "Hello"
REINDEX
LIST I1, C1

* Even setting order off doesn't show "Hello" #2
SET ORDER TO
LIST I1, C1

* If we reopen the table, then we can see "Hello" #2
USE UniqueEx
LIST I1, C1

* End code


Regards-
Nancy Folsom
Pixel Dust Industries
Author _Debugging_Visual_FoxPro_Applications_
http://www.hentzenwerke.com/catalogpricelists/debugvfp.htm



 
©2004 Nancy Folsom
<-- Prior Message New Search Next Message -->