relational calculus
DESCRIPTION
Relational Calculus. Logic Calculus. Logic ( 논리학 ) Propositional Calculus ( 명제계산 ), Predicate Calculus ( 술어계산 ) Propositional calculus proposition( 명제 ) can be classified as true or false Syllogism ( 삼단논법 ) If Socrates is a human, Socrates will die. (p->q) Socrates is a human. (p) - PowerPoint PPT PresentationTRANSCRIPT
Relational Calcu-lus
데이터베이스시스템 2Calculus
Logic Calculus Logic ( 논리학 )
Propositional Calculus ( 명제계산 ),Predicate Calculus ( 술어계산 )
Propositional calculusproposition( 명제 ) can be classified as true or false
Syllogism ( 삼단논법 )If Socrates is a human, Socrates will die. (p-
>q)Socrates is a human. (p)Socrates will die. ( (p->q)∧p) -> q
데이터베이스시스템 3Calculus
Syllogism ( 삼단논법 )
Truth table( 진리표 )
Predicate Calculuspropositional calculus + quantifiers such as EXISTS, FORALL
p q p –> q (p –> q) AND p ((p –> q) AND p) –> q
T T T T T
T F F F T
F T T F T
F F T F T
데이터베이스시스템 4Calculus
Predicate Calculus
예 : 모든 사람은 죽는다 . Socratest 는 사람이다 . 따라서 , Socrates 는 죽는다 .propositional calculus 로는 증명할 수 없다 .
증명 H(x) : x 는 사람이다 . M(x) : x 는 죽는다 .
1) ( x) (H(x) –> M(x))
2) H(s)
3) H(s) –> M(s) by 1) & 2) Universal Instantiation
4) M(s) by 2) & 3) propositional logic
데이터베이스시스템 5Calculus
Relational Algebra vs. Relational Calculus
Algebra operators are applied to relations in a speci-
fied order (procedural) Calculus
select all the tuples which make the speci-fied condition true (non-procedural)
tuple calculus vs. domain calculus
데이터베이스시스템 6Calculus
Relational Calculus Tuple variable
a variable which represents a tuple of a rela-tion
x 학생 ( 학번 , 이름 , 학년 , 학과 )y 과목 ( 과목번호 , 과목이름 , 학점수 , 학과 ,
담당교수 )z 수강 ( 학번 , 과목번호 , 성적 , 중간성적 ,
기말성적 ) Examples1) List all the student names.
x 학생 , { x. 이름 }2) List the student_numbers of students who
take ‘C413’ z 수강 , { z. 학번 | z. 과목번호 = ‘C413’ }
데이터베이스시스템 7Calculus
집합 표시
1 12
y x
1( , ) | 1, 0, 0
2x y y x x y
데이터베이스시스템 8Calculus
Relational Calculusx 학생 ( 학번 , 이름 , 학년 , 학과 )y 과목 ( 과목번호 , 과목이름 , 학점수 , 학과 , 담당교수 )z 수강 ( 학번 , 과목번호 , 성적 , 중간성적 , 기말성적 )
3) List the names and the departments of stu-dents who are not in ‘컴퓨터’ departmentx 학생 , { (x. 이름 , x. 학과 ) | x. 학과 <> ‘컴퓨터’ }
4) List the student_number and class_number pairs such that indicated student got higher than or equal to 90 in either the midterm or the final of the indicated classz 수강 , { (z. 학번 , z. 과목번호 ) | z. 중간성적 >= 90 or z. 기말성적 >= 90 }
데이터베이스시스템 9Calculus
Relational Calculusx 학생 ( 학번 , 이름 , 학년 , 학과 )y 과목 ( 과목번호 , 과목이름 , 학점 , 학과 , 담당교수 )z 수강 ( 학번 , 과목번호 , 성적 , 중간성적 , 기말성적 )
5) List the student_numbers of students who got ‘A’ in the class ‘C413’z 수강 , { z. 학번 | z. 과목번호 = ‘C413’ and z. 학점 = ‘A’ }
6) List the names and departments of students who take ‘C413’ x 학생 , z 수강 , { (x. 이름 , x. 학과 ) | EXISTS z (z. 학번 =x. 학번 and z. 과목번호 = ‘C413’) } join In EXISTS
데이터베이스시스템 10Calculus
Relational Calculusx 학생 ( 학번 , 이름 , 학년 , 학과 )y 과목 ( 과목번호 , 과목이름 , 학점 , 학과 , 담당교수 )z 수강 ( 학번 , 과목번호 , 성적 , 중간성적 , 기말성적 )
7) Find the student name which comes first in the alphabetical order. x1, x2 학생 , { x1. 이름 | FORALL x2 (x1. 이름 <= x2. 이름 ) }
Quantifiers ( 정량자 )EXISTS V(p) (existential quantifier, 존재정량자 ) :
There exists at least one value V that makes p true.
FORALL V(p) (univeral quantifier, 범용정량자 ) : For all values of V, p evaluates true.
데이터베이스시스템 11Calculus
Relational Calculusx 학생 ( 학번 , 이름 , 학년 , 학과 )y 과목 ( 과목번호 , 과목이름 , 학점 , 학과 , 담당교수 )z 수강 ( 학번 , 과목번호 , 성적 , 중간성적 , 기말성적 )8) List the student_numbers and the names of students
who do not take ‘C413’. x 학생 , z 수강 , { (x. 학번 , x. 이름 )| NOT EXISTS z (z. 학번 =x. 학번 and z. 과목번호 = ‘C413’ )} Difference Not In Not EXISTS
9) List the names of students who take at least one class from ‘컴퓨터’ departmentx 학생 , y 과목 , z 수강 , { x. 이름 | EXISTS z (z. 학번 =x. 학번 and EXISTS y (y. 과목번호 = z. 과목번호 and y. 학과 = ‘컴퓨터’ ) ) }
데이터베이스시스템 12Calculus
Relational Calculusx 학생 ( 학번 , 이름 , 학년 , 학과 )y 과목 ( 과목번호 , 과목이름 , 학점 , 학과 , 담당교수 )z 수강 ( 학번 , 과목번호 , 성적 , 중간성적 , 기말성적 )10) List the names of students who take at least one
class together with the student of student_number 100. x 학생 , z1 수강 , z2 수강 , { x. 이름 | EXISTS z1 (z1. 학번 =x. 학번 and EXISTS z2 (z2. 과목번호 = z1. 과목번호 and z2. 학번 = 100 ) ) }
11) List the names of students who take all the listed classes in 과목 relation Algebra : ( 수강 [ 학번 , 과목번호 ] / 과목 [ 과목번호 ] ) Join 학생 ) [ 이름 ]Calculusx 학생 , y 과목 , z 수강 , { x. 이름 | FORALL y (EXISTS z ( z. 과목번호 = y. 과목번호 and z. 학번 =x.학번 ) )}
데이터베이스시스템 13Calculus
Relational Calculusx 학생 ( 학번 , 이름 , 학년 , 학과 )y 과목 ( 과목번호 , 과목이름 , 학점 , 학과 , 담당교수 )z 수강 ( 학번 , 과목번호 , 성적 , 중간성적 , 기말성적 )
( 수강 [ 학번 , 과목번호 ] / 과목 [ 과목번호 ] ) join 학생 ) [ 이름 ]
x 학생 , y 과목 , z 수강 , { x. 이름 | FORALL y (EXISTS z ( z. 과목번호 = y. 과목번호 and z. 학번 =x.학번 }
FORALL V(p) NOT EXISTS V(Not p){ x. 이름 | Not EXISTS y (Not EXISTS z (
z. 과목번호 = y. 과목번호 and z. 학번 =x.학번 }
Denominator is the relation for the first NOT EX-ISTS.
데이터베이스시스템 14Calculus
Relational Calculusx 학생 ( 학번 , 이름 , 학년 , 학과 )y 과목 ( 과목번호 , 과목이름 , 학점 , 학과 , 담당교수 )z 수강 ( 학번 , 과목번호 , 성적 , 중간성적 , 기말성적 )
FORALL V(p) NOT EXISTS V(Not p)All dogs are animals There are no dogs which are not animalstakes all the subjects There are no subjects
which are not takenNames of students Names of studentswho take such that
all the subjects there are no subjects not taken by each of
them.