Relational databases: a key and a relationship
도입됨
4:42
데이터베이스
학교 도서관은 대출 기록을 하나의 스프레드시트에 보관한다. 각 행에는 학생 이름, 학급, 도서명, 날짜가 포함된다. 학생이 학급을 변경할 때, 수십 개의 행이…
영어 내레이션 · 영어와 중국어 자막 전환 가능
이 수업의 내용
| English | 의미 |
|---|---|
| relational database/rɪˈleɪʃənl ˈdeɪtəbeɪs/ | A database that organises data into tables connected through matching key values. |
| primary key/ˈpraɪməri kiː/ | 주키 |
| foreign key/ˈfɒrən kiː/ | 외부 키 |
| record/ˈrekɔːd/ | A stored collection of information about an item, person or event. |
| field/fiːld/ | A named item of data within a database record. |
| normalisation/ˌnɔːməlaɪˈzeɪʃn/ | Organising relational database tables to reduce unnecessary duplication and avoid update, insertion and deletion anomalies. |
이 현상을 설명할 수 있는 이유는 무엇인가?
- 주소 변경 시 각 주문에 사용자 주소를 복제하면 충돌되는 레코드가 생성될 수 있습니다.
What did Codd propose in 1970?
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
The relational model.
모델 만들기
- 관계형 테이블은 행(row)과 속성(attribute)으로 구성됩니다.
- 주 키(primary key) 는 행을 식별하며, 외부 키(foreign key) 는 다른 테이블의 참조 키에 연결됩니다.
- 정규화는 의미 있는 관계를 유지하면서 피할 수 있는 중복성과 수정 이상을 줄일 수 있습니다.
- primary key: 테이블 행을 고유하게 식별하는 속성의 집합입니다.
- foreign key: 다른 테이블의 키를 참조하는 속성의 집합입니다.
Which field is the best primary key for Students?
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
It is unique and does not change.
검증 가능한 증거 선택하기
- 조인(join)은 지정된 조건에 따라 행들을 결합합니다.
- 결과 행 수는 관계의 카디널리티(cardinality)와 필터에 따라 달라집니다.
- 외부 키 제약 조건(foreign key constraint)은 관계 규칙을 강제하지만, 개인 데이터를 자동으로 암호화하지는 않습니다.
실험실 작업: 실제 개인정보가 없는 작은 가상의 사용자-주문 데이터를 설계하십시오. 키를 선언하고, 중복 삽입 및 누락된 참조 삽입을 테스트한 후, 수작업으로 산출한 예상 표와 쿼리 결과를 비교하십시오.
A foreign key holds the primary key of another table.
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
It links the tables.
알려진 값으로부터 시작하기
- 주어진 정보: 네 명의 고객이 각각 2, 0, 3, 1 건의 주문을 가지고 있습니다.
- 고객에서 주문으로의 내부 조인(inner join)은 2 + 0 + 3 + 1 = 6 개의 행을 반환합니다.
- 좌측 조인은 주문이 없는 고객도 NULL 매칭 행으로 유지하므로, 여기에는 7가 됩니다.
당신의 차례: 세 명의 고객이 각각 1, 3, 2 건의 주문을 가지고 있습니다. 고객-주문 내부 조인(inner join)은 몇 개의 행을 반환합니까?
One source row, several matches
Each source row contributes one result per matching record. A left join retains an unmatched source row as one NULL-matched row.
What problem does normalisation prevent?
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
Store each fact once.
결론 및 한계 확인
- 주 키는 반드시 사람 이름일 필요는 없습니다.
- 조인은 단순히 테이블을 연결하는 것이 아닙니다.
- 원본 문자열로 SQL을 구성하기보다 신뢰할 수 없는 입력에는 파라미터화된 쿼리를 사용하십시오.
틀린 설명: 외래 키는 모든 행을 자동으로 암호화합니다. 외래 키는 테이블 간의 참조 링크이며, 참조되는 행이 존재하도록 강제합니다. 암호화는 수행하지 않으며, 행 내용 보호는 별도의 보안 기능입니다.
- 관계형 테이블은 행(row)과 속성(attribute)으로 구성됩니다.
- 조인(join)은 지정된 조건에 따라 행들을 결합합니다.
- 주의: 주 키는 반드시 사람 이름일 필요는 없습니다.
Four students have 0, 2, 2 and 3 enrolments. How many rows does an inner join of Students and Enrolments return?
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
0 + 2 + 2 + 3 = 7; the student with none is omitted.
Why is Ben missing from the join result?
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
An inner join returns only matches.
이 카드는 새로 추가되어 번역이 준비될 때까지 영어로 표시됩니다.
Integrity and transactions
- Referential integrity: an enrolment cannot refer to a StudentID that does not exist.
- A transaction is all-or-nothing (atomic): moving a student between classes must not leave them in both or neither.
An atomic transaction either completes fully or not at all.
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
No half-moved records.
이 카드는 새로 추가되어 번역이 준비될 때까지 영어로 표시됩니다.
A name is not a key. Two students can share a name, and names change. Use a unique identifier that never changes as the primary key.
이 카드는 새로 추가되어 번역이 준비될 때까지 영어로 표시됩니다.
A relational database stores entities in tables of records and fields. A primary key identifies each record; a foreign key links tables; normalisation removes repetition; an inner join returns only matching rows; integrity rules and atomic transactions keep data consistent.
Design tables for a school library (books, members, loans) with primary and foreign keys, and write a query listing the titles borrowed by member 42.
Tables, keys, query.
어떤 문제가 있었나요? 사이트 팀만 이 내용을 볼 수 있습니다.