Cascade Record and Image DeletesIn this example we will look at deleting a category in a typical product catalog with Product_Categories, Products, and Versions. Having more than one table imposes difficulties that can only be overcome by a little hand coding and modification of stock UD behaviors. This tutorial details how to set up the relationships in an Access database for cascade deletes of related records [*] and how to implement server side code to delete images associated with related records. [†] I will set up some conventions to make it easy to follow the tutorial. This tutorial assumes you have created a recordset navigation page to select the record you want to delete and a method to select the desired record. It assumes you have added a form to the delete page with a method to submit the delete. It assumes you have created an Access database with the described table structure or your customized version of it. Color conventions will be used to make following the tutorial as simple as possible. Stock UltraDev code blocks that are not modified in this tutorial will be black. Tutorial code will be blue. Comments pertinent to the tutorial will be grey. We will begin with the Access database.
|
||
|
[*] The Access Upsizing Wizard will convert the relationships to triggers when upsizing the Access database to SQL Server removing any need to write the SQL statements. [†] This same method of coding will work with structures that have fewer or more tables by merely adding or taking away recordsets and loops. |
This tutorial is the third of a three part series on image delete options. Unlike the other two tutorials we will be not working with George Petrov's Pure ASP upload behavior on this page. Instead we will look at how to remove related records and the images associated with them when deleting a master record. By controlling orphaned records we keep the database tables clean and our applications run faster with fewer resources consumed. It only makes sense to remove images associated with the deleted records as well, again conserving server resources.

shown
in the heading of this section. It is found in the main toolbar. The
relationships wizard will appear as shown above. Highlight and add the
tables for which you want to define relationships. Add the Product_Categories,
Products, and Versions tables to the relationships layout window. Next
click on the Category_ID field of the Product_Categories table and drag
the icon that appears at your mouse pointer to the Category_ID field
of the Products table. The define relationships window will open.
Save
your changes and close Access.
James W. Threadgill has authored numerous tutorials on ASP and ASP.NET web development, published on such sites as the Dynamic Zones and MSDN Accademic Alliance. He co-authored the Sam's book Dreamweaver MX: ASP.NET Web Development.

Comments
Kenny Darcy
RE: RE: DMX 2004 and the Cascade delete
re " I wouldn't expect DMX to make this sort of thing point and click anytime soon."
I have found the MX Kollection from Interakt does just that.
regards
Kenny
James W. Threadgill
RE: DMX 2004 and the Cascade delete
You are welcome, Kenny. I was quite ill when you posted, but I'm back now!
Cascading file deletes are pretty complex considering the loops required. I wouldn't expect DMX to make this sort of thing point and click anytime soon.
Kenny Darcy
DMX 2004 and the Cascade delete
Firstly thank you for your tutorials, I am very grateful. I am going to give the Cascade Record and Images deletes a go and was wondering, using mx2004 has things changed any to make it a little easier to do this.
Regards
Kenny