Introduction Procedural Query language query specification involves giving a step by step process of obtaining the query result e.g., relational algebra usage calls for detailed knowledge of the operators involved difficult for the use of non-experts Declarative Query language query specification involves giving the logical conditions the results are required to satisfy easy for the use of non-experts
Prof P Sreenivasa Kumar, Department of CS&E, IITM. 1
TRC – a declarative query language
Tuple variable – associated with a relation ( called the range relation ) • takes tuples from the range relation as its values • t: tuple variable over relation r with scheme R(A,B,C ) t.A stands for value of column A etc TRC Query – basic form: { t1.Ai1, t2.Ai2,…tm.Aim | θ } predicate calculus expression involving tuple variables t1, t2,…, tm, tm+1,…,ts - specifies the condition to be satisfied
Prof P Sreenivasa Kumar, Department of CS&E, IITM. 2
An example TRC query student (rollNo, name, degree, year, sex, deptNo, advisor ) department (deptId, name, hod, phone )
Obtain the rollNo, name of all girl students in the Maths Dept (deptId = 2) {s.rollNo,s.name| student(s)^ s.sex=‘F’^ s.deptNo=2}
attributes required in the result
This predicate is true whenever value of s is a tuple from the student relation, false otherwise In general, if t is a tuple variable with range relation r, r( t ) is taken as a predicate which is true if and only if the value of t is a tuple in r
Prof P Sreenivasa Kumar, Department of CS&E, IITM. 3
General form of the condition in TRC queries
Atomic expressions are the following: 1. r ( t ) -true if t is a tuple in the relation instance r 2. t1. Ai t2 .Aj compOp is one of {, ≥, =, ≠ } 3. t.Ai c c is a constant of appropriate type Composite expressions: 1. Any atomic expression 2. F1 ∧ F2 ,, F1 ∨ F2 , ¬ F1 where F1 and F2 are expressions 3. (∀t) (F), (∃t) (F) where F is an expression and t is a tuple