Deleting Records in master-Detail tables

I have a master table and a number of Detail tables.When I  delete a record in the
master table i want to simaltaneously delete the relevant child table records.
I tried to use Locate method of Table to find a matching record
and then use Delete method.But it is not executing.
Where am I going wrong?

The code snippet is given below


      if detailTable.Locate('Ser',tempSer,searchOptions)
                                     ShowMessage('NO record to be deleted');
end;//of procedure
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

kretzschmarConnect With a Mentor Commented:
well venks,

glad to helped you and
that you got it work.

supwangs suggestion should also work,
(there is no coding to do,
because that is a definition in the database)
but is not supported by all databases.

good luck

meikl ;-)
Why no use the Cascade Update Rule?  Run the DataBase Desktop and search
"Referential Integrity dialog box" in the help.


Cascade specifies that any change you make to the value in the key of the parent table is automatically made in the child table. If you delete a value in the key of the parent table, dependent records in the child table are also deleted. Cascade is the default update rule.
To cascade an update across tables, Database Desktop must place a lock on the target table. If the lock is denied (because another user has already placed a lock), Database Desktop cannot perform the cascade update.

If you are working with SQL tables, the availability of cascading updates and deletes varies according to the table type and software version.
hi venks,

try as follows
(a faster and better method)

- drop additional a tquery on your form
- select as datasource the datasource of your master
- type in as sqlstatement : delete from detailtablename where ser = :ser

now if you want to delete the derails for the seklected masterrecord you can simple use this code

Showmessage(inttoStr(query1.rowsaffected)+' records deleted');

try it

venksAuthor Commented:
Dear Supwang and meikl
Your answer does not tell me how to do the coding>I knew about cascade delete.Cascade delete is used to protect accidental deletion of master table when data is present in child tables.
I took the advice of meikl(using Tquery component) and got the job done.
He deserves the points though he did not answer my question regarding using table methods for deletion.But certainly Tquery is easier to use.
meikl,if you post an answer i will award you the points
Thanks to both of you
All Courses

From novice to tech pro — start learning today.