😵 ~23.11.10

0823-24 | 데이터베이스 정규화

unikue 2023. 8. 27. 10:44

✅ 정규화란?

  • 데이터를 모아서 사용 ▶ 표준화의 필요성 제기
  • 데이터베이스에서 말하는 테이블의 가장 표준화된 방식은 무엇? ▶ 파일과의 차이를 줄인다 ▶ 차이는? 중복!
  • 중복이 있음으로써 결함이 발생했다 ▶ 중복을 제거해서 데이터의 결함을 제거
  • 중복이 발생되는 원인 : 참조하다보면 중복이 발생됨 ▶ 데이터베이스를 더 잘게 쪼갠다

👉 따라서 표준에 맞춰서 중복을 제거한다

중복이 제거된 파일 형태가 표준이고, 그 표준을 맞추고자 하는 것이 표준화 == 정규화

 

💥 4정규화 이상으로 넘어가면 너무 잘게쪼개지는 현상이 발생하기도 함

 

 

 

Database normalization - Wikipedia

From Wikipedia, the free encyclopedia Reduction of data redundancy This article needs attention from an expert in Databases. See the talk page for details. WikiProject Databases may be able to help recruit an expert. (March 2018) Database normalization or

en.wikipedia.org

 


 

#️⃣ 1정규화

하나의 필드가 여러 값들의 집합을 담고 있어서는 안된다

 each field contains a single value. A field may not contain a set of values or a nested record.

 

👉 1정규화 위반으로 자격사항, 주문내역, 파일첨부, 팔로잉 아이디 모두 다른 테이블로 만들어져야 한다

1정규화를 통해 나눠진 테이블

 

⏩ 데이터에서 도메인 이란?

: 유효한 값의 범위를 의미하는 기호. 

👉 변수; 속성; 필드; property -- 각자가 값의 범위를 갖는다

 

 

 


 

 

#️⃣ 2정규화

: 복합키를 가지고 있는 테이블만 해당된다

: 복합키중 하나의 키에 의해 컬럼이 늘어난다면 결함의 요인이 된다

 

The Book table below has a composite key of {Title, Format} (indicated by the underlining), which will not satisfy 2NF if some subset of that key is a determinant. At this point in our design the key is not finalised as the primary key, so it is called a candidate key. 

 

All of the attributes that are not part of the candidate key depend on Title, but only Price also depends on Format. To conform to 2NF and remove duplicates, every non-candidate-key attribute must depend on the whole candidate key, not just part of it.

To normalize this table, make {Title} a (simple) candidate key (the primary key) so that every non-candidate-key attribute depends on the whole candidate key, and remove Price into a separate table so that its dependency on Format can be preserved:

 

👉  book 테이블은 후보키 2개로 식별이 되고 있는데, 대개 title을 기준으로 나눠지고 있지만 price는 format에 따라 달라지는 형태를 보이고 있다. 모든 속성은 후보키 전체에 의존해야지 이렇게 일부 후보키에만 의존하는 경우가 있으면 안됨. 

👉 일부키에 의존하는 경우는 새로 테이블을 만든다.

 

2정규화를 통해 새로 생성된 테이블

 

 


 

 

#️⃣ 3정규화

: 해당 테이블에 관련 없는 속성은 존재하면 안됨

: 한 속성이 두가지 속성에 해당되면 안됨. (반대로 말하면 값을 찾아가기위해 두번 건너가선 안됨)

 

The Book table still has a transitive functional dependency ({Author Nationality} is dependent on {Author}, which is dependent on {Title}). A similar violation exists for genre ({Genre Name} is dependent on {Genre ID}, which is dependent on {Title}). Hence, the Book table is not in 3NF.

👉 Book table에서 AuthorNationality는 Author에 속하고 Title에도 속하며 Book에 있을 속성이 아니다.

장르 이름도 장르 ID에 속하는 속성이며 Title에 따라 나눠지기도 한다. 테이블을 따로 만들어서 참조키를 통해 찾아갈 수 있는 관계로 만들어야 한다.