Storing conditional logic expressions/rules in a database

前端 未结 5 643
说谎
说谎 2021-02-05 17:13

How can I store logical expressions using a RDBMS?

I tag objects and would like to be able to build truth statements based on those tags. (These might be considered as

5条回答
  •  情话喂你
    2021-02-05 18:01

    As a default, until I've understood a problem well enough to figure out the solution, I would not store business rules in the database. These belong in code. There are always exceptions to any rule however and you could use your RDBMS' stored procedures and / or functions to encapsulate these rules (provided your DB has them). But, as I said, ideally, you would interpret the data in a meaningful way in code.

    Update

    Sorry, realise I didn't answer your question. You could use functions, if your DB has them, that allow you to pass in parameters and return scalar values, or use stored procedures. You might have 1 per expression and a larger procedure to combine the expressions in some way.

提交回复
热议问题