<p>I feel like I have a very basic/stupid question, yet I never saw/read/heard anything in this direction.</p>

<p>Say I have a table <em>users(userId, name)</em> and a table <em>preferences(id, userId, language)</em>. The example is trivial but could be extended to a situation with multi-level relations and way more tables..<br>
When my UI requests to delete a user I first want to show a warning stating that also its preferences will be deleted. If at some point the database gets extended with more tables and relationships, but the software isn't adapted accordingly (the client didn't update) a generic message should be shown.</p>

<p>How can I implement this? The UI cannot know about the whole data structure and should not be bothered to walk down all the relations to manually delete all the depending records.    </p>

<p>I would think this would be with constraints.<br>
The constraint would be <em>no action</em> at first so the constraint will throw an error that can be caught by the UI. After the UI receives a confirmation, the constraint should become a <em>cascade</em>.</p>

<p>Somehow I'm feeling like I'm getting this all wrong..</p>

[{'answer_id': 81586, 'author': 'RB.', 'author_id': 15393, 'author_profile': 'https://Stackoverflow.com/users/15393', 'pm_score': 1, 'selected': False, 'text': '<p>What I would do is this:</p>\n\n<ol>\n<li>The constraint is CASCADE</li>\n<li>The application checks if preferences exist.</li>\n<li>If they do, show the warning.</li>\n<li>If no preferences exist, or the warning is accepted, delete the client.</li>\n</ol>\n\n<p>Changing database relationships on the fly is not going to be a good idea!!</p>\n\n<p>Cheers,</p>\n\n<p>RB.</p>\n'}, {'answer_id': 81665, 'author': 'hamishmcn', 'author_id': 3590, 'author_profile': 'https://Stackoverflow.com/users/3590', 'pm_score': 0, 'selected': False, 'text': '<p>If you are worried about the user not realising the full impact of their delete, you might want to consider not actually deleting the data - instead you could simply set a flag on a column called say "<code>marked_for_deletion</code>". (the entries could then be deleted a safe time later)<br>\nThe downside is that you need to remember to filter out the marked rows in other queries. This can be mitigated by creating a view on the table with the marked rows filtered out, and then always using the view in your queries.</p>\n'}]
['https://Stackoverflow.com/questions/81560', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11333/']