Microsoft KB Archive/148894

= How to Enforce Uniqueness in Visual FoxPro Memo Fields =

Article ID: 148894

Article Last Modified on 9/30/2003

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 3.0b Standard Edition

-



This article was previously published under Q148894



SUMMARY
This article shows by example how to enforce uniqueness in memo fields.



Example Scenario
When you have a long character field that happens to be rarely filled, it might be better to store the data in a memo field instead of a character field. The memo field takes up only four bytes in the table, and the large character field can now be removed from the structure.

You can use the following step-by-step procedure to create a unique index tag on just a portion of the data in the memo field. The benefits of this process are:


 * Guaranteed uniqueness in large data sets.
 * The tag size remains the same as it was.
 * The size of the .dbf file shrinks dramatically.

Step-by-Step Procedure
 Create a new database (.dbc file):  On the File menu, click New. Select Database, and then click the New File button. Place the new database (.dbc file) in the directory of your choice.  Add a table to the database:  Right-click the Database Designer, and select New Table.</li> Click the New Table button.</li> Create the table in the directory of your choice.</li> In the Table Designer, add a memo field.</li></ol> </li> Add a Unique Index Tag to the Table:  Click the Index tab.</li> Under Name, type the name of your memo field.</li> Under Type, select Primary or Candidate (Unique won't work).</li>  For the expression, enter the following where MaxLen is any value up to the maximum of 240: PADR(MemoField, MaxLen) </li></ol> </li> Add several records to the table with exactly the same content in the memo field to verify a proper setup.</li></ol>

Additional query words: VFoxWin

Keywords: KB148894

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.