Master detail relationships DB

Chapter twelve of the free Delphi Database Course for beginners. How to use parent-child database relationships to deal effectively with the problem of joining two database tables to present information.

Master-detail data relationships are a fact of life for every Delphi database developer; just as data relationships are a fundamental feature of relational databases.

In the previous chapters of this course, we've invariably used only one table from our "demo" aboutdelphi.mdb MS Access database. In real time database programming, the data in one table is related to the data in other tables. In general, tables can be related in one of three different ways: one-to-one, one-to-many or many-to-many. This chapter will show you how to use one-to-many database relationships to deal effectively with the problem of joining two database tables to present information.

A one-to-many relationship, often referred to as a "master-detail" or "parent-child" relationship, is the most usual relationship between two tables in a database.

Common scenarios include customer/purchase data, patient/medical-record data, and student/course-result data. For example, each customer is associated with at least one order record. Valued customers have many order records involving significant sums and often a user needs to view one in connection with the other. In a one-to-many relationship, a record in Table A can have (none or one or) more than one matching record in Table B, but for every record in Table B there is exactly one record in Table A.

A typical master-detail data browsing form displays the results of a one-to-many relationship, where one DBGrid displays (or set of data enabled controls) the results of the first or master table. It then tracks a selection in the first DBGrid to filter the results of a second table used to display the details of the selection in the second DBGrid.

When working with the BDE and Delphi, the simplest way to assemble a master-detail form is to use the Database Form Wizard. Wizard simplifies the steps needed to create a tabular or data-entry form by use of an existing database, unfortunately it is designed to use the BDE versions of TTable and TQuery components. Everything the wizard does, we can do by hand.

Since, through this course, we are working with the ADOExpress set of Delphi components, we'll need to set all the components step by step. Firstly we have to make sure that we have two tables in a master-detail relationship.

Was this article helpful?

0 0

Post a comment