On 26 Nov 2015, at 7:42am, nomad at null.net wrote:

> Which column in the customers table should contain the fixed value or
> expression?

The items listed in the REFERENCES clause should be handled in the same order 
as they would if they were all column names.  It's just that instead of looking 
all of them up in the child table, some of them can be fixed strings.

Suppose you have a table with three types of customer and a "can discount" 
column.  Both dealers and agents have 'yes' in it and private buyers have 'no'.

I want to make sure that discounts are entered only for customers who may have 
them.  This can be enforced by a REFERENCES clause, but at the moment I do it 
by keeping a redundant column in my discount table, set to 'yes' on every row. 
I then use REFERENCES to relate this to the "can discount" column in the 
customer table.

This technique is elegant, it explains the business process in the schema, 
which makes it easier on external programs reading my database, and it requires 
less programming in my programming language.  But in SQLite it requires extra 
space: one extra value for every entry in the discount table.

Simon.

Reply via email to