ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 제 1 정규화
    CS/데이터베이스 2022. 6. 12. 13:05
    728x90

    제 1 정규화

    릴레이션의 모든 도메인이 더 이상 분해될 수 없는 원자 값(atomic value)만으로 구성되어야 한다.

     

     

     

    topic table

    title type description created author_id author_name author_profile price tag
    MySQL paper MySQL is... 2011 1 kim developer 10000 rdb, free
    MySQL online MySQL is... 2011 1 kim developer 0 rdb, free
    ORACLE online ORACLE is... 2012 1 kim developer 0 rdb, commercial

     

    위의 정규화 되지 않은 topic table은 tag가 atomic 하지 않아 제 1 정규형을 만족하지 않는다.

     

    SELECT * FROM topic WHERE tag = 'free'

    SELECT * FROM topic ORDER BY tag

    다른 테이블과 JOIN 등 의 연산을 할 때 문제가 발생한다.

     

    위의 테이블을 제 1 정규형을 만족시키는 방법은 

     

    First normal form

     

    1. 똑같은 행을 생성한다.

     

    title type description created author_id author_name author_profile price tag
    MySQL paper MySQL is... 2011 1 kim developer 10000 rdb
    MySQL online MySQL is... 2011 1 kim developer 0 free
    ORACLE online ORACLE is... 2012 1 kim developer 0 rdb
    ORACLE online ORACLE is... 2012 1 kim developer 0 commercial

     

    하지만 이 방법은 정보의 손실은 없지만 정보의 중복이 발생하여 바람직한 방법은 아니다.

     

     

    2. 필드를 추가

     

    title type description created author_id author_name author_profile price tag1 tag2
    MySQL paper MySQL is... 2011 1 kim developer 10000 rdb free
    ORACLE online ORACLE is... 2012 1 kim developer 0 rdb commercial

     

    하지만 이 방법은 테이블의 컬럼의 구조를 변경시켜야 하고(테이블의 전체를 변경시켜야함) 혹여나 tag값이 원래 한개만 있던 컬럼은 tag2에 NULL이 오게 되어 낭비가 발생해 유연함이 떨어진다.

     

     

    3. 테이블을 쪼개고 매핑 테이블을 만든다.

     

    topic 과 tag 테이블은 M:N 관계이므로 테이블을 쪼개고 매핑 테이블(topic_tag_relation)을 만든다.

     

    topic 테이블 자체는 title과 type을 중복한 중복키를 PK로 가지고 있지만 tag는 title에 의존하고 있고, topic과 tag를 매핑하기 때문에 tag 테이블의 ID 값 이 두 개를 가져와서 topic_tag_relation PK로 만든다

     

     

    topic

    title type description created author_id author_name author_profile price
    MySQL paper MySQL is... 2011 1 kim developer 10000
    MySQL online MySQL is... 2011 1 kim developer 0
    ORACLE online ORACLE is... 2012 1 kim developer 0

     

    topic_tag_relation

    topic_title tag_id
    MySQL 1
    MySQL 2
    ORACLE 1
    ORACLE 3

     

    tag

    id tag
    1 rdb
    2 free
    3 commercial

     

     

     

     

    참고

    https://www.youtube.com/watch?v=FYDHJbIwm5Y&t=18s

    728x90

    'CS > 데이터베이스' 카테고리의 다른 글

    조인의 종류와 원리  (0) 2022.06.14
    데이터베이스의 기본  (0) 2022.06.11
    RDBMS vs NoSQL  (0) 2022.04.13

    댓글

oguuk Tistory.