0

I have a product table and it is foreign key for product ingredients table.

Is there a way to check if it is fk referenced before making isdeleted = true without manually querying for it?

0

2 Answers 2

0

You could require the UPDATE to reference a subquery that will return no results if references exist. Then, if 0 rows are updated, you can raise a message to the UI to report an error.

0
0

Short answer is no - code must be written somewhere. A constraint (using a UDF) or a trigger could prevent this.

In my experience, soft-deletes are usually done to keep ALL of an object's attributes and related bits in the database.

Requiring the related bits to be physically removed seems to defeat the purpose - but no one knows your system and its design.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.