venks
asked on
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
var
tempser:variant;
searchOptions:TLocateOptio ns;
Begin
tempSer:=MasterTable.Field ByName('Se r').AsInte ger;
if detailTable.Locate('Ser',t empSer,sea rchOptions )
then
detailTable.Delete;
else
ShowMessage('NO record to be deleted');
end;//of procedure
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
var
tempser:variant;
searchOptions:TLocateOptio
Begin
tempSer:=MasterTable.Field
if detailTable.Locate('Ser',t
then
detailTable.Delete;
else
ShowMessage('NO record to be deleted');
end;//of procedure
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
query1.ExecSQL;
Showmessage(inttoStr(query 1.rowsaffe cted)+' records deleted');
try it
meikl
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
query1.ExecSQL;
Showmessage(inttoStr(query
try it
meikl
ASKER
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
venks
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
venks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
"Referential Integrity dialog box" in the help.
--------------------------
Cascade
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.
--------------------------