You are here:About>Computing & Technology>Delphi Programming
About.comDelphi Programming
Master-detail relationships ADO and Delphi
Page 1: One-to-Many relationships - why and when?
 More of this Feature
• Page 2: Realtions in Access
• Page 3: ADO master-detail
 Join the Discussion
"Post your views and comments to this chapter of the free Delphi database Programming Course"
Discuss!
 Related Resources
• free DB Course.TOC
• more Database articles

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.

Next page > One-to-many in MS Access > Page 1, 2, 3

DB Course Next Chapter >>
>> New...Access Database from Delphi

From Zarko Gajic,
Your Guide to Delphi Programming.
FREE Newsletter. Sign Up Now!
Newsletters & RSSEmail to a friendSubmit to Digg
 All Topics | Email Article | | |
Advertising Info | News & Events | Work at About | SiteMap | Reprints | HelpOur Story | Be a Guide
User Agreement | Ethics Policy | Patent Info. | Privacy Policy©2008 About, Inc., A part of The New York Times Company. All rights reserved.