We help IT Professionals succeed at work.

need to understand the relationship amoung tables in a database.

Hi Experts,
I am maintaining a Delphi7 application which workes with tables in a paradox datbase using BDE.
In order to make sure that my application does not violate the referential integrity of a database, my guess is that I need to understand the relationship amoung the tables in the database. Is this correct? and if yes, How do you achieve that in a paradox database?
Watch Question

Top Expert 2004

?? didn't understand the question

even in paradox you can define releationships between tables,
which are watched by the paradox-engine,
so you do not need to care about the relations within your delphi-app
(you may get an exception if you are about to avoid the defined relation)

so what is the question?

meikl ;-)

Table relationships (database relationships) can be related in three ways:
One-to-One, One-to-Many and Many-to-Many.
I usualy write my answers but since there are many well documented pages about this topic, I am posting his link.


I hope it will guide you in right direction.
 Unfortunately the llinks between tables can be supported by the database engine (recommended), by the programmer (in situations where Paradox may not support the relation the way you want to), or be unenforced.  The only way to understand the relationships (speaking as a developer who has had to come into undocumented projects many, many times) is to examine the database first, then the code that uses it.  Does the company own a copy of Paradox?  If it does then you can use it to see what relationships have been set up from within Paradox.  If it does not then it is llikely that the database files were set up with a limited tool, or even with raw code.  If that is the case then it is likely that any referential integrity is being handled in the code.  If you are unable to find any referential integrity in the database or in the code then there likely is none.

  Sorry about the long answer.  The short version is this, you will have to look.  I hope that what I wrote gives you a plan of attack at least.
Firstly how are you editing the table definitions for your Paradox Tables? With Delphi 7 you should have a copy of Database Desktop, otherwise there are other tools, including the JEDI Database Desktop which you can download here: http://sourceforge.net/projects/jedidbd/ (although I still recommend the normal Database Desktop).
When you edit a table in DD, you can see if any dependancies on any field exist which will tell if  there are any referential integrity settings for a field.
But this only tells half the story because it's entirely possible that the developer took care of referential integrity from within the application (which is not the best-practise way to do it, but is not entirely uncommon to technically do both).

What kind of datasets are used in the application, for example TTable? You could have a master-detail relationship of two tables. In case you don't know, that's where you have two TTables (the one being the master, the other being the detail), and with the detail TTable you set the MasterTable setting in the object inspectior to the master table, and you set the KEY to a field which is common in both tables.
So in one example your Master Table could be your Customer's Table, and the detail table could be Customer's Orders, and you would link them via the field Customer ID (as the Key).
In this way you can have a Top DB Grid where the user selects a customer, and
a bottom DB Grid which shows all the orders for that customer.
If the user tries to delete a customer, you would add a BeforeDelete event to the customer (master) table that says
  if MyDetailTable.RecordCount > 0 then
    showmessage('You cannot delete this customer while it has orders. Try deleting the orders first');

In this way, not only have you maintained referential integrity, but you've also customised this for the user instead of getting a generic message back from the BDE saying something generic about referential integrity and confusing the user.

Hope that helps.

Otherwise just ask


Thank you so much to all of you for your very informative answers, even though I did not state my question very clearly.
I use paradox and Database desktop. Is there a way in Database Desktop to find out the relationships amoung the tables in the database. For example if table1 is a master to table2 which is a master to table3 which is a master to table4 and table2 is also a master to table7. and so on. Is there a way in Database desktop to find out these relationships, other that just looking at all the table for hours and still miss some relationships.
Thanks again for all the help.
Top Expert 2004
you need Entity-Relation-Diagramm
don't know yet, if the database-Desktop is able for this
maybe there is a tool  able for this . . . somewhere

are the relations defined?
as far as i know Database desktop.has a two table dialog for defining a relation

meikl ;-)


The relations do exist. Now if that is not the same as being defined, that how do I find out if they are defined?
How do I get the Entity-Relation-Diagramm?
Try Case Studio (citation: This software is for all developers, database designers and for all who want to create and maintain their database structures effectively), see if it is what you want.




Thanks guys for the very informative answers.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.