DB - Lecture2
데이터베이스 2일차
Relations and Relational Algebra
Relation
relation 을 매우 쉽게 생각하면 그냥 collection of tuples having same attributes 이다.
-
Relation 을 표시하는데 Table 을 사용한다.
-
Row == Tuple
-
Column == Attribute
-
Degree of a relation
- column 갯수
- Binary Relation: 2 dgeree
- Ternary Relation: 3 degree
-
Cardinality of a relation
- row 갯수
Data Manipulation (relational algebra)
- Data 를 relation 으로 표현하면, Algebra 이론을 통해 data를 매우 쉽게 조작(manipulate)할 수 있다.
- Number Algera Manipulation: +, -, /, *
- Boolean Algebra Manipulation: &, |, !
- Relational Algebra Manipulation
- Union, Intersection, Difference, Projection, Selection, Product
Union-compatible relations
- Domain 이 같아야 한다 == degree 와 attributes 가 같아야한다.
- 이 조건을 만족해야 다음 manipulation 이 가능하다.
- Union
- Difference
- Intersection
Relation-specific operators
Union
"SQL 레벨업" 책에서는 조건 분기를 UNION 으로 하고 있다면, CASE 구문을 사용하여 처리하도록 고쳐야한다고 한다.
SELECT p_name AS name FROM programmer
UNION
SELECT s_name AS name FROM student;
Intersection
오라클에서만 지원되고, MySQL 에서는 지원되지 않는다고 한다.
SELECT p_name AS name FROM programmer
INTERSECT
SELECT s_name AS name FROM student;
Difference
오라클에서만 지원되고, MySQL 에서는 지원되지 않는다고 한다.
SELECT p_name AS name FROM programmer
MINUS
SELECT s_name AS name FROM student;
Projection
SELECT (column names) FROM (table name)
테이블에서 정보를 가져올 때 * 이 아니라, 가져올 attribute 를 마음껏 정할 수 있는게 projection 이다.
Selection
SELECT * FROM (table name) WHERE (unary operator)
WHERE 문을 쓸 수 있다는게 Selection 이다.
- Row Selector (unary operator)
Cartesian Product
CROSS JOIN
이 Cartesian Product 연산이다.- Union-compatible 하지 않아도 사용가능한 연산이다.
- Cartesian Product 를 새로운 tuple 로 표현하면 너무 더러워지므로, flatten 하는 과정을 거친다. 이를 Extended Cartesian Product 라고 한다.
결론
Relational operator 를 통해 연산한 결과는 다시 relation 이다!
Author And Source
이 문제에 관하여(DB - Lecture2), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@pyro/Database-Lecture2저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)