Is there a simple call I could make that would tell me if there are dependent child records, without me having to hard code in all the child tables and manually calling each child table one at a time.
A .net framework call that that returned a Yes/No to a "Are there any dependent records?" sort of query, or better still if it told me the table the dependent record is in.
I would then know if I could delete the record.
I have referential integrity turned on and am using a Access 2000 .mdb, but will soon be upsizeing to SQL Server Express (the MSDE thingy).
I realise I could use the sledge hammer technique and let the Referential Integrity stop me, but a more polite approach would be better, and I am not sure if you can have Referential Integrity in SQL Express like you do in Access.
Warm regards
NeilReferential integrity in SQL Server Express is pretty much the same as Access, although you'll have more methods available for creating and maintaining the constraints (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/createdb/cm_8_des_04_9183.asp).
If you want to delete all child records associated with a parent record, you can use cascading deletes (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/createdb/cm_8_des_04_92ib.asp). This is not a good idea as a rule though, since most times you'll want the application to throw an exception if a parent record is deleted before the child records. In a typical application, you'd delete the child records first, then delete the parent record(s).
If this is a UI, I always like it when developers catch the RI exception if a user attempts to delete a parent, then displays a message such as "there are other records associated with the row you want to delete, all associated data will be deleted, are you sure this is OK?".
Hope this helps,
Josh Lindenmuth
No comments:
Post a Comment