That is incorrect.  Whether or not the customer "can_discount" is an attribute 
of the customer.  Whether or not a sale "has_discount" applied is an attribute 
of the sale.  They are not the same attribute, do not mean the same things, and 
are attributes of different tables.  

Business logic (implemented in the application or a trigger) can assure that 
you do not allow a sale to "has_discount" when the customer is not allowed 
"can_discount", but the relationship (FK) from the sale to the customer is the 
customer number (or whatever unique identifier you have assigned to the 
customer.

You need to normalize your data better.

> -----Original Message-----
> From: sqlite-users-bounces at mailinglists.sqlite.org [mailto:sqlite-users-
> bounces at mailinglists.sqlite.org] On Behalf Of Simon Slavin
> Sent: Thursday, 26 November, 2015 06:57
> To: SQLite mailing list
> Subject: Re: [sqlite] FOREIGN KEY enhancement request
> 
> 
> On 26 Nov 2015, at 1:52pm, Bernardo Sulzbach <mafagafogigante at gmail.com>
> wrote:
> 
> > I did not mean that. But if you want to check that a certain row has a
> > valid value like you described,
> >
> >    check ((job='dealer' or job='agent') or can_discount='no')
> 
> That works only when the "job" column is in the table the constraint is
> in.  In my case, there are two tables: client and sale.  The "job" column
> is in the client table, but it's the sale table where I need to know if
> the client deserves a discount.
> 
> Simon.
> _______________________________________________
> sqlite-users mailing list
> sqlite-users at mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users



Reply via email to