Could someone explain to me WHEN do you use existential and universal quantifiers for Relational Calculus? Given this schema:Hotel(hotelNo, hotelName, city)The expression below gets all hotel names based in London (expressed in Domain Relational Calculus)$$\mathrm{HotelName|(\exists hNo,cty)(Hotel(hNo,hotelName,cty)\wedge cty=\,\,\!\!London\!)}$$Why does the existential quantifier required for this example? Wouldn't this be the equivalent {hotelName | (Hotel(hNo, hotelName, cty) AND cty='London')}And why is only hNoand cty selected for the existential quantifier? What about the hotelName? Source: Herts University - Advanced Database Course
When should you use the existential and universal quantifiers for Relational Calculus?
database theory;databases;relational algebra
This question is related to the very basics of database theory, finite model theory and logics. I would strongly suggest Abiteboul's book on Foundations of Databases, or Libkin's book on Finite Model Theory.Very roughly stated, a database is a collection of facts, and a query is a logical formula, which is used to specify certain patterns to be matched against the database. The most common database query language is unions of conjunctive queries, which is simply a disjunction of conjunctive queries. These are existentially quantified queries and there is NO universal quantification at all. The query in the question is indeed the simple conjunctive query$\exists \ x \ {Hotel(x, y, london)} $where $x$ and $y$ are logical variables and $london$ is a constant. Intuitively, the $x$ variables are to be matched to hotel numbers, and $y$ variables to hotel names. Now, in this formula, $y$ is a free variable, i.e. it is not bound to any quantifier. It is wrong to assume that it is bound to a universal quantifier. Such variables are also called the answer variables as these are the variables for which you want to retrieve answers. Note that $x$ is not an answer variable; so, you are not interested in the hotel numbers. All you want to say with this query is: Give me all the names of the hotels in London! Differently, consider this query ${Hotel(x, y, london)} $where $x$ is also a free variable. It asks for all names + numbers of the hotels in London. A Boolean query is a special case of a conjunctive query that does not contain any free variables. For instance, the query$\exists \ x,y \ {Hotel(x, y, london)} $has no free variables and asks a yes/no question: Is there a hotel in London (with some hotel number and name)? Overall, please have a look at the reference books, and simply learn the query semantics.