Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / General DB Topics / DB Theory / May 2008

Tip: Looking for answers? Try searching our database.

Business Rules

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lars Tackmann - 27 Mar 2008 14:22 GMT
Hi

This is a recurring question here, but I have read through the archive
and failed to find a answer so here goes.
Consider the following use cases:

- When a customer purchases product A he automatically gets product B
- Product C can only be bought with product A (either if you have A
already or in the same order)
- Product D cannot be bought with C
- When you purchase X number of product type E then you can not
purchase more than Y of product type F
- A certain product combination (number and types) should yield a
discount.

as seen there exists the concept of a single product and that of a
product type (family of products), the business rules should be able
to work on both single products and on product types. The question now
is how best to deal with such rules from a DB point of view, is there
a relational design general enough to cope with such rules ? or do I
have to resolve to stored  procedures and constraints ?.

I am not on the lookout for a complete solution, I simply see allot of
business rules like the ones defined above, but never a clean
solution to maintaining them (perhaps a DSL or a rule engine is the
way to go).

Any feedback will be greatly appreciated.

--
Yours sincerely

Lars Tackmann
Tegiri Nenashi - 27 Mar 2008 15:50 GMT
> Hi
>
[quoted text clipped - 17 lines]
> a relational design general enough to cope with such rules ? or do I
> have to resolve to stored  procedures and constraints ?.

In theory, the any database constraint is an inequality

E1 <= E2

where E1 and E2 are RA expressions involving database relations. In
logical programming terms the partial order <= is the familiar
implication symbol.

In practice, there is a lot of technical details to work out no matter
what approach would you take, being that constraint enforcement via
triggers or via ANSI SQL style assertions (implemeted as check
constraints on materialized views).

I suggest that any rule-engine technology that does not naturally
embrace databases would give you the most headache. There is a reason
why rule engines never being able to crawl out of their tiny niche and
enjoy wider adoption.
Tegiri Nenashi - 27 Mar 2008 16:12 GMT
> In practice, there is a lot of technical details to work out no matter
> what approach would you take, being that constraint enforcement via
> triggers or via ANSI SQL style assertions (implemeted as check
> constraints on materialized views).

Perhaps I can suggest some literature.

"Applied Mathematics for Database Professionals" by Lex de Haan & Toon
Koppelaars covers a lot of material on constraints. Frankly, I don't
see the point of their constraint classification scheme based on
constraint appearance. Database wide constraint is an equation/
inequality involving more than one relation, single relation wide
constraint refer to a sinle relvar. Tuple-level constraints can be
identified if we operate expression on relational calculus level, but
not RA?

"SQL Design Patterns: Expert Guide to SQL Programming" by Vadim
Tropashko contains a chapter on constraint enforcement via ANSI SQL
style assertions implemeted as check
constraints on materialized views.

(I picture Joe Celko reading this and feverishly starting typing a new
book about constraints. BTW, "Thinking in Sets" -- nice title!)
Lars Tackmann - 28 Mar 2008 17:42 GMT
> > In practice, there is a lot of technical details to work out no matter
> > what approach would you take, being that constraint enforcement via
[quoted text clipped - 19 lines]
> (I picture Joe Celko reading this and feverishly starting typing a new
> book about constraints. BTW, "Thinking in Sets" -- nice title!)

Thanks to all posters for the suggestions, of particular interest was
the book titles. I know I
am not going to find the one solution to conquer all business rules,
but hopefully I can learn
how to stay out of the spaghetti mess of application/database logic I
so often face whenever I
see such rules implemented in real life.

--
Lars Tackmann
Tegiri Nenashi - 28 Mar 2008 20:12 GMT
> but hopefully I can learn
> how to stay out of the spaghetti mess of application/database logic I
> so often face whenever I
> see such rules implemented in real life.

The "spaghetti mess" epithet was the exact motivaton to employ some
proprietory rule-based engine on a project I was involved a decade
ago. We used to joke that the guy who maintained the rules for this
engine is guraranteed the employment with the company forever. The
project indeed was quietly scrapped after the leading developer
leaving, and there were several lessons to learn from that failure.
Using priopritory or niche technology as project fundation was
obvious, but my most vivid impression was the inability of rule
engines to do simple things that we take for granted in traditional
procedural languages. Rule engines have no loops, no exception
handling, no modular code structuring. They have no debugging
facility. Therefore, yes, you can have business rules coded as
spaghetty, but there are well established facilities to manage this
complexity, whereas in rules engine case after you scale above 1000
rules, your project is essentially out of control.

My diatribe doesn't apply to database-as-business-rules-repository,
however, this idea currently exists only on paper (C.J. Date book
"What Not How: The Business Rules Approach to Application
Development").
Jon Heggland - 27 Mar 2008 16:02 GMT
> The question now
> is how best to deal with such rules from a DB point of view, is there
> a relational design general enough to cope with such rules ? or do I
> have to resolve to stored  procedures and constraints ?.

Stored procedures (or operators in general) and constraints are part of
relational design; not something that comes in addition, as a last resort.
Signature

Jon

topmind - 29 Mar 2008 08:14 GMT
> Hi
>
[quoted text clipped - 24 lines]
>
> Any feedback will be greatly appreciated.

I would suggest creating a little sub-language via subroutines for
validation for a given product or order. Example:

IF (anyOf("footware,halloween,product4625") Or allOf("shirts,coupon"))
And anyOf("discount4") THEN logError("Federal law 234X prohibits
type-4 discounts on these items per trade fight with France")

The end result will look like some kind of Boolean expression and/or
set-oriented language, perhaps with some string list parsing
capabilities. Whether it's possible to do this easily with SQL, I'd
have to look at your actual system.

This is in conjunction with a many-to-many table for product
classifications.

> --
> Yours sincerely
>
> Lars Tackmann

-T-
Kenneth Downs - 21 May 2008 21:18 GMT
> Hi
>
[quoted text clipped - 17 lines]
> a relational design general enough to cope with such rules ? or do I
> have to resolve to stored  procedures and constraints ?.

I would rephrase the question to ask if you've come up with a concrete
table design that can hold these options.  Are they hypothetical, or are
these the actual requirements for a real system?

The first looks like a cross-reference from products to products, no?
So that is easy enough to store.  An insert or update trigger that
queries the table and adds more lines (unless already present) should
not be that hard.

The second, if I am not mistaken, is identical to the first, except that
it requires the user's consent to purchase an additional item?
Otherwise it would be the same as the first one.  The trick would be
that it looks in their sales history to satisfy the behavior.  Again a
simple cross-reference table stores the rule, a small trigger implements it.

The third rule is again another cross-reference.  Maybe all three kinds
of rules are in the same table with a column to say the rule type.

The fourth rule is starting to sound like you're making this up, but I
don't know what business this is in and I've seen some strange ones, so
I suppose it must be real.  This looks superficially like a super-case
of rule 3.  Adding quantities to the cross reference causes rule 3 to
reduce to a case of this rule.

For the last one, one way or another you have to query quantities and
group by product category.  You can do it in a view, in SQL in a
trigger, or anywhere else.

> I am not on the lookout for a complete solution, I simply see allot of
> business rules like the ones defined above, but never a clean
[quoted text clipped - 7 lines]
>
> Lars Tackmann
David Cressey - 23 May 2008 12:39 GMT
> > Hi
> >
[quoted text clipped - 57 lines]
> >
> > Lars Tackmann

I am not sure what follows is responsive to your question,  but I offer it
as a possibility.

Some databases I have worked with distinguish between "parts" and
"products".  A feature of a "product" is that is can be sold and bought.
Products consist of one or more parts.  parts may contain other parts, and
so on.  Services,  like the right to attend a given offering of a given
course,  may be included in "products"  by including parts that are
intangible.

The rules you have suggested such as prerequisites and mutual exclusions,
apply to the formation of groups of parts... and not to the formation of
collections of products.  In such a framework,  the fact that a given person
is buying two pills that should not be taken together is a relationship
between parts,  not a relationship between products.

And, in reality,  the problem there is not that person X is buying two
pills.  It's the likelihood that the same person will swallow both pills.
That would be true even if the person stole the pills, or made one of them
himself.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.