HOWTO: Setting a Primary Key to Updateable in a View

Last reviewed: October 8, 1997
Article ID: Q174689
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, versions 5.0, 5.0a
  • Microsoft Visual FoxPro for Macintosh, version 3.0b

SUMMARY

By default, when creating a view on a table, any field with a primary key index is not marked as updateable. This article illustrates how you can mark the primary key as updateable through the View Designer, and programmatically.

MORE INFORMATION

View Designer

To mark the primary key as updateable through the View Designer interface, use the following steps:

  1. Open the view in the View Designer.

  2. Click the Update Criteria tab.

  3. Click the Update column beside the primary key field. NOTE: The Update column has a column header that looks like a pencil.

Programmatically

To mark the primary key as updateable programmatically, use the following steps:

  1. Open the Tastrade database in the VFP\Samples\Tastrade\Data folder.

  2. Run the following program to create a new SQL view based on the Customer table.

          ***********RunFirst.prg***********
          CREATE SQL VIEW MYTEST AS SELECT * FROM CUSTOMER
          DBSETPROP("MYTEST","VIEW","SENDUPDATES",.T.)
          ***********End RunFirst.prg*************
    

  3. Modify the view in the View Designer and note that the primary key is not marked for updates.

  4. Create a program called MarkPrimary and place the following code in it:

          ************MarkPrimary.prg****************
          PARAMETERS ViewName
    

          x=ALIAS()
          USE IN 0 &viewname
          PrimKeys = CURSORGETPROP('KeyFieldList',viewname)
          i=1
          remField=PrimKeys
          DO WHILE i <> 0
    
             nextcomma=AT(remField,",")
             IF nextcomma=0 and len(remfield)=0 THEN
                i=0
                EXIT
             ELSE
                IF nextcomma=0 and LEN(remfield)<>0 then
                   tmpfield=remfield
                   y= DBSETPROP(ViewName + "." + ;
                   tmpField,'Field','UPDATABLE',.T.)
                   i=0
                   EXIT
                ELSE
                   tmpField=SUBSTR(remField,i,NextComma -1)
                   remfield=SUBSTR(remfield,nextcomma + 1)
                   i=nextcomma
                   y= DBSETPROP(ViewName + "." + ;
                   tmpField,'Field','UPDATABLE',.T.)
                ENDIF
             ENDIF
          ENDDO
    
          SELECT  (viewname)
          USE
          IF NOT EMPTY(x) THEN
             SELECT  (x)
          ENDIF
          **************End MarkPrimary.prg*******************
    
    

  5. Run the MarkPrimary.prg code by typing the following into the Command window:

          DO MARKPRIMARY WITH "MYTEST"
    

  6. Modify the view MyTest in the View Designer and notice that the primary key field is now marked for updates.

Keywords          : FxprgTable VFoxMac vfoxwin kbcode
Version           : MACINTOSH:3.0b; WINDOWS:5.0,5.0a
Platform          : MACINTOSH WINDOWS
Issue type        : kbhowto


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 8, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.