![]() This is the default behaviour and you'll get a "Cannot add or update a child row: a foreign key contraint fails" if you do. ![]() You need to move or delete the dependent rows first in order to remove the parent. Just like you can't delete a directory if it contains files. Like was already explained it simply prohibits you to delete a parent if it has childs. If you don't have the Order, then having the OrderLine's makes no sense. You use this when it makes no sense to keep the child row if the parent row is removed. ON DELETE depends on how the relations between your rows exists: Now that you know this on to your question. Just like you would map an entity from a request when interfacing with a REST API. If you use a (powerful) ORM you'll be able to translate these procedures and views to entities using a ResultSetMapper. Your application should only know it's interface like every other REST API out there. Define your database with proper referential integrity, events, views, and procedures as the database is optimised for this type of task. Your application should only be database aware, not be the database. If I have multiple applications (or even more relevant, multiple people) performing queries, then ON DELETE CASCADE likely makes sense.ĭo you know of any other reasons why one would recommend using ON DELETE CASCADE? I believe that it does matter who executes a query. Presumably, using ON DELETE CASCADE may result in the opposite? Not trying to go round and round in a debate just trying to better cement my own approach. You imply that not using ON DELETE CASCADE results in highly visible, easy to change, one place in code. Added them trying to give context, but probably shouldn't have. Yea, my first two statements with an "Agree?" question were more of a SQL question. It's highly visible, easy to change, and with proper modelling needs only be implemented in one place in code. What matters is who you entrust to maintain data integrity: do you want your application's code to do all the work, or do you want your database to do all the work? Programmers typically prefer the former, DBAs typically prefer the latter. ![]() I disagree about the "this is more of a PHP question and not really a SQL question" part. So it's not about the type of the key or the origin of the query.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |