| Index
» Projects
» phpMyEdit
» Forum
» Writer - books problem |
 |
lanbo
Joined: 08 Jan 2004
Posts: 4
Posted: 2004-01-08 13:30
Back to top
Reply with quote
|
Hi all,
Remember my last problem?
------------
Imagine table writers: IDwriter, name, surname
And table books: IDbook, IDwriter, bookname
One writer may have written many books.
-------------
OK. Now, if I remove a writer in table WRITERS, how can I automatically remove all his/her BOOKS in table BOOKS?
Which approach would you 'experts' take? ;-)
Thanks in advance and happy new year to you all!!!
|
michal
Joined: 17 Jun 2003
Posts: 537
Location: Slovakia
Posted: 2004-01-09 18:39
Back to top
Reply with quote
|
triggers should be used for this purpose. in your trigger delete after make a sql query to delete those records.
see documentation in http://opensource.platon.sk/projects/doc.php/phpMyEdit/html/configuration.triggers.html
and one forum questions concerning triggers as examples.
|
ajh
Joined: 17 Dec 2003
Posts: 236
Posted: 2004-01-09 21:26
Back to top
Reply with quote
|
Just looking at the MySQL manual, if you use InnoDB tables in your database, you can actually create tables with foreign key constraints, so you could cascade delete the books if the writer is deleted. This would be much safer than using a trigger as if for some reason the trigger didn't run, but the main delete did, you would have a whole load of headless book records.
|
|
Post new topic
Reply to topic
|
|
|
|