Master-detail relationships ADO and Delphi
Page 2: MS Access relationships and referential integrity
More of this Feature
• Page 1: Data relationships
• 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
MS Access relationships
Our focus will be on the following two tables: Customers and Orders. Both tables are a part of the DBDEMOS database that comes with Delphi.
Since both tables are Paradox tables, we'll use the code from the previous article to port them to our working aboutdelphi.mdb MS Access
database.
Notice that when you port those
tables to Access both of them have no index or primary key nor are they linked in any way in Access.
The power in a relational database management system such as MS Access comes from its ability to quickly find and bring together information stored in separate tables. In order for MS Access to work most efficiently, each table in your database should include a field or set of fields that uniquely identifies each individual record stored in the table. If two tables are liked in a relation (of
http://delphi.about.com/library/weekly/aa071001b.htm (1 of 4) [24.11.2002 17:10:16]
in this topic
Graphics
Internet/Intranet Mathematics Multimedia
Delphi Pascal/IDE Screen saver dev.
VCL Using
VCL Write/Enhance Web Services Windows/Shell/API Kylix (D on Linux)
Coding standards Books/Publications Dev. Utilities
FAQs/Tips/Tricks Free Code Projects Humor and Fun Icons and Glyphs Jobs and Offers Training/CD/Video VCL & Tools
Subject Library All articles on this topic
any kind) we should set that relation with the MS Access.
Customers-Orders relation
To set up the relationship, you add the field or fields that make up the primary key on the "one" side of the relationship to the table on the "many" side of the relationship. In our case, you would add the CustNo field from the Customers table to the Orders table, because one customer has many orders. Note that you have to set the CustNo in Customers to be the primary key for the table.
When creating a relation between two tables MS Access provides us with the Referential Integrity feature. This feature prevents adding records to a detail table for which there is no matching record in the master table. It will also cause the key fields in the detail table to be changed when the corresponding key fields in the master are changed - this is commonly referred to as a cascading update. The second options is to enable cascading deletes. This causes the deletion of all the related records in a detail table when the corresponding record in the master table gets deleted. These events occur automatically, requiring no intervention by a Delphi application using these tables.
Now, when we have all the relations set up, we simply link few data components to create a master-detail data browsing Delphi form.
Next page > Master-detail with AdoExpress > Page 1, 2, 3
DB Course Next Chapter >>
>> New...Access Database from Delphi
All graphics (if any) in this feature created by Zarko Gajic.
More Delphi
http://delphi.about.com/library/weekly/aa071001b.htm (2 of 4) [24.11.2002 17:10:16]
Stay up-to-date!
Subscribe to our newsletter.
Advertising
> Free Credit Report
> Free Psychics
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time. Start a chat now!
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC.
· NEXT ARTICLE: Real-time 2D particle systems (with gravitation!).
This tutorial is going to discuss a library of Delphi routines that will help you create your own particle systems. The term system is defined to mean, 'A group of interacting, interrelated, or interdependent elements forming a complex whole'. You can use the particle to represent a cannonball being shot out of a cannon - in trajectory games.
Stay informed with all new and interesting things about Delphi (for free).
Subscribe to the About Programming Newsletter
Name Email
Got some code to share? Got a question? Need some help?
Recent Discussions
Delphi Programming
Join these forum conversations
Extracting digital audio from cd
Delphi disadvantages compared to VS.Net Keep An Application Always On Top Delphi7 adoblob problem
Searching in a text file or wide string
Email this page!
Explore More on the About Network!
http://delphi.about.com/library/weekly/aa071001b.htm (3 of 4) [24.11.2002 17:10:16]
Enter Email Go!
subscribe
Related Sites
C/C++
Focus on Java Focus on Linux Focus on Windows HTML/XML
Brand New Malibu
Auto Buying Guide Philip Powell takes a closer look at
Chevrolet's sexy new 2004 Malibu.
Road Radio
Driving this Thanksgiving?
Radio Guide Corey Deitz explains how to find the right station.
Weird Science
Paranormal Guide Steven Wagner looks at strange scientific experiments throughout history.
Search About
About Us | Advertise on This Site | User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright © 2002 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.
http://delphi.about.com/library/weekly/aa071001b.htm (4 of 4) [24.11.2002 17:10:16]
Explore more...
About > Computing & Technology > Delphi Programming