Академический Документы
Профессиональный Документы
Культура Документы
SUBJECT:
Database System (IT-243)
SUBMITTED BY:
Haider Farooq……………18661556-056
SUBMITTED TO:
Mam Ayesha Rashid
SECTION:
BS 18 (A)
DEPARTMENT:
INFORMATION TECHNOLOGY
QUESTION NO 1:
Relational Algebra:
It is widely used procedural query language. It collects instances of relations as
input and gives occurrences of relations as output. It uses various operations to
perform this action. SQL Relational algebra query operations are performed
recursively on a relation. The output of these operations is a new relation, which
might be formed from one or more input relations.
SELECTION:
The SELECT operation is used for selecting a subset of the tuples according to
a given selection condition.
EXAMPLE:
PROJECTION:
The projection eliminates all attributes of the input relation but those mentioned
in the projection list. The projection method defines a relation that contains a
vertical subset of Relation.
1 Google Active
2 Amazon Active
3 Apple Inactive
4 Alibaba Active
Table A Table B
1 1 1 1
1 2 1 3
A ∪ B gives
Table A ∪ B
column 1 column 2
1 1
1 2
1 3
QUESTION NO 2:
Relational calculus:
Higher-level declarative language for specifying relational queries.
Tuple Relational Calculus is a non-procedural query language
unlike relational algebra. Thus, it generates set of all tuples t, such that
Predicate P(t) is true for t. P(t) may have various conditions logically
combined with OR (∨), AND (∧), NOT (¬).
Relational Algebra and Relational Calculus are the formal query
languages for a relational model. Both form the base for the SQL
language which is used in most of the relational DBMSs. Relational
Algebra is a procedural language. On the other hands, Relational
Calculus is a declarative language.
Relational Calculus exists in two forms:
Syntax:
{ T | condition}
Example:
If our table is Student, we would put it as Student(T)
Then comes the condition part, to specify a condition applicable for a
particular attribute(column), we can use the. dot variable with the tuple
variable to specify it, like in table Student, if we want to get data for
students with age greater than 17, then, we can write it as,
T.age>17, where T is our tuple variable.
Domain Relational Calculus:
In domain relational calculus, filtering is done based on the domain of the
attributes and not based on the type values.
Syntax:
{c1, c2, c3 ……, cn} | F {c1, c2, c3, ……, cn}
o Where c1, c2…etc. represents domain of attributes and F defines the
formula including the condition for fetching the data.
EXAMPLE:
o Again, the above query will return the names and ages of students in the
table Students who are older than 17.