relational-databasetuple-relational-calculus

How do you define a (1,6) cardinality using Relational calculus


I have these three tables:

 Customer
 Rent
 Book

The cardinality between the Customer and the Rent table is (1,6) and the cardinality between the Rent and the Book table is (1,infinity).

Using relational calculus's syntax, I would define a (0,1) cardinality like this:

∀x∀y∀z(rent(x,y)∧rent(x,z) → y =z)

But how can I define a (1,6) cardinality?


Solution

  • You could express it (in predicate calculus, as you have expressed your question) in this way:

    ∀ x (x ∈ Customers →  ∃ y rent(x,y))
    
    ∧
    
    ∀ x (x ∈ Customers → cardinality ({ y | rent(x,y)}) ≤ 6)
    

    If you prefer, you can write the condition cardinality(set) ≤ n with a complex logical expression of the form:

    ∀y1∀y2 ... ∀yn (rent(x,y1) ∧ rent(x,y2) ∧ ... ∧ rent(x,yn)
                      ∧ y1 ≠ y2 ^ ... (all the possible pairs) ... 
      → ∄ ys (rent(x,ys)  ∧ ys ≠ y1 ^ ys ≠ y2 ^ ... ^ ys ≠ yn)
    

    or in a more concise way (see the note of @philipxy):

    ∀y0∀y1 ... ∀yn (rent(x,y0) ∧ rent(x,y1) ∧ ... ∧ rent(x,yn) → y0 = y1 ∨ ...