Microsoft KB Archive/194515

= BUG: Invalid ALTER TABLE Command Works and Corrupts DBC =

Article ID: 194515

Article Last Modified on 5/12/2003

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 3.0b Standard Edition
 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 5.0a
 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q194515



SYMPTOMS
After issuing an invalid ALTER TABLE statement, running VALIDATE DATABASE fails and returns an error.



RESOLUTION
To avoid creating an invalid object through the ALTER TABLE command, be sure to include an expression in the Add Foreign Key statement.

To remove the invalid object reference in the database, follow the steps listed below:


 * 1) Note the object number in the error below: it is Object #14.
 * 2) Use the database as a table.
 * 3) Delete the record for Object #14 (if that is the object number in the error)
 * 4) Pack the database.

Fix Code For "Steps To Reproduce" Sample
CLOSE DATABASE ALL USE testdb.DBC DELETE FOR objectid=14 &&Delete object #14's record PACK USE



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.



MORE INFORMATION
The ALTER TABLE command allows the entry of an Add Foreign Key statement without specifying an expression. This causes an invalid entry in the database referencing a relationship that does not exist. This causes the VALIDATE DATABASE command to return the following error:

"Object #14 (Relation 'Relation 1'): Cannot find associated Index referenced by this object"

Steps to Reproduce Behavior
  Run the following code in a program file: #DEFINE DBCNAME   'testdb' #DEFINE TABNAME   'testtab' #DEFINE TABCOUNT     2

CLEAR CLOSE DATA ALL DELETE FILE testdb.DBC DELETE FILE testdb.dc?

CREATE DATABASE DBCNAME

FOR lni = 1 TO TABCOUNT DELETE FILE (TABNAME+ALLTR(STR(lni)))+'.dbf' DELETE FILE (TABNAME+ALLTR(STR(lni)))+'.cdx' CREATE TABLE (TABNAME+ALLTR(STR(lni))) (F1 C(10) NOT NULL ;           PRIMARY KEY, ;            F2 C(10) NOT NULL) ENDFOR

* Gives invalid DBC because Foreign key expression is missing ALTER TABLE (TABNAME+("2")) ADD FOREIGN KEY TAG ; F2 REFERENCES (TABNAME+"1") TAG F1                        Issue the "VALIDATE DATABASE" command from the Command window. Note that this command returns the following error:

"Object #14 (Relation 'Relation 1'): Cannot find associated Index referenced by this object"



