Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Referential Integrity
Message
From
21/08/2000 21:17:47
 
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00372982
Message ID:
00407577
Views:
34
Thank You for taking the time to post this reply. It is Very helpful!!

Thank You
Roelaux

>>I need to define referential integrity within my program. Lookin at the help, it says to go to the Database Designer screen. Can someone give more specifics.
>>
>
>Referential Integrity defines the behavior of two tables; it's defined in the Database Container, and is implemented as a set of triggered procedures that occur when add, delete or update events fire because of changes to fields or record states in related tables.
>
>Create a database (.DBC). In the Database Designer, add or create the tables which need to be interrelated. In the parent table, create an index on a field which will act as its Primary key - you must ensure that each record in this table has a unique value for the primary key at all times; you cannot allow duplications in it.
>
>In the child table, create an index on a field of the same type and length as the primary key of the parent table as a Regular index. This will serve as the Foreign key - the link from the child records back to the parent record in the first table that is responsible for them.
>
>Select the primary key index entry in the parent table by clicking and holding the mouse button down. Drag the Primary key index entry to the desired foreign key index entry in the child table, and release the mouse button. A link will be established.
>
>At this point, you can right click in the database container and select Edit Referential Integrity. A Grid will appear showing all the relationships defined in the database. Each row represents a relationship. Each relationship has three event columns which can be set up:
>
>Update - this establishes the required behavior when the primary key in the parent table is changed. it can be (I)gnore, in which case nothing is to be done automagically, (R)estrict, which will prevent the change from occuring if the parent owns any child records, or (C)ascade, in which case the foreign keys of the owned child records are changed to the new value.
>
>Delete - this defines the behavior when a parent record is marked for deletion. (I)gnore causes no automagic action to occur; (R)estrict disallows the deletion of a parent record which currently owns any child records, and (C) ascade deletes all children of the parent being deleted.
>
>Insert - this establishes the requirements when adding a new child record. (I)gnore does nothing as previously noted. (R)estrict disallows the addition of a child record where the record does not have the value of a current record in the parent table.
>
>You can make these adjustments through the page tabs rather than the comboboxes.
>
>When you finish defining referential integrity for the database, VFP will prompt you to save the changes, and it then generates the appropriate code and adds it as stored procedures to the database container. These stored procedures will fire any time the tables in the relationships for the DBC are changed and will enforce the requested rules automatically whenever changes are madethrough VFP or VFP's ODBC drivers.
>
>The RI code is generated from standard source generators which ship with your VFP development system. There are third-party offerings that can replace the default RI handlers with their own routines, and offer alternative mechanisms of enforcing desired RI behavior; the book "Effective Techniques for Application Development with Visual FoxPro 6.0" by Jim Booth and Steve Sawyer covers RI and what makes it really work well. It's a very good resource for VFP developers at all levels. It comes both in print and in the form of a .CHM file making it an on-line reference, and all source can be downloaded, including significant enhancements added to the code after initial publication.
>
>>When I am in the Data Environment I try to double click the relationship line buy nothing happens.
>>
>>Thanks
Previous
Reply
Map
View

Click here to load this message in the networking platform