Tech Tip: How to get a listing of all relations in a database
PRODUCT: 4D | VERSION: 12 | PLATFORM: Mac & Win
Published On: July 22, 2011
Wouldn't it be nice to have a listing of all the relations in a database? The following proceedures will provide a listing of all the relations in a database in a 4D list box.
First create a project form and on that form create an array based list box with zero columns. Next, on the form install three buttons, titled; "Primary", "Remote", and "All."
In the "Primary" button place the following code. The listing will be of all primary keys that have an attached relationship.
Begin SQL SELECT * FROM _USER_CONSTRAINTS WHERE CONSTRAINT_TYPE = 'P' INTO LISTBOX :ListBox_Relations; End SQL |

In the "Remote" button place the following code. The listing will be of all remote or foreign keys that have an attached relationship.
Begin SQL SELECT * FROM _USER_CONSTRAINTS WHERE CONSTRAINT_TYPE = 'R' INTO LISTBOX :ListBox_Relations; End SQL |

In the "All" button place the following code. The listing will be of a full listing of all relationships in the database. Depending on the history of the database some relations may have a CONSTRAINT_TYPE of 4DR. The code below will show all constraint types.
Begin SQL SELECT * FROM _USER_CONSTRAINTS INTO LISTBOX :ListBox_Relations; End SQL |
