Tables, keys and relationships · 테이블, 키 및 관계
More than one table
Real databases split data across several tables. This lesson uses a small shop with two of them:
customer— one row per customer (id,name,city)orders— one row per order (id,customer_id,order_date,total)
Storing the customer's name on every order would repeat it again and again. Keeping customers in their own table stores each one once.
여러 테이블
실제 데이터베이스는 데이터를 여러 테이블에 분산하여 저장합니다. 이 수업에서는 두 개의 테이블을 사용하는 작은 상점을 사용합니다:
customer— 고객당 한 행 (id,name,city)orders— 주문당 한 행 (id,customer_id,order_date,total)
모든 주문에 고객의 이름을 저장하면 반복적으로 중복됩니다. 고객을 별도의 테이블에 보관하면 각 정보를 한 번만 저장합니다.
Primary keys
A primary key is the column that uniquely identifies each row. It is never blank and never repeated.
customer.idis the primary key ofcustomer.orders.idis the primary key oforders.
Given a primary key value, you can always find exactly one row.
주 키(Primary Keys)
주 키는 각 행을 유니크하게 식별하는 열입니다. 공백일 수 없으며重複될 수도 없습니다.
customer.id은customer의 주 키입니다.orders.id은orders의 주 키입니다.
주 키 값을 알면 항상 정확히 한 행을 찾을 수 있습니다.
Foreign keys
A foreign key is a column that holds the primary key of another table, linking the two.
orders.customer_id holds a value from customer.id — it says which customer each order belongs to.
Referential integrity means every foreign-key value must match a real primary key: an order can't belong to a customer who doesn't exist.
외래 키(Foreign Keys)
외래 키는 다른 테이블의 주 키를 저장하여 두 테이블을 연결하는 열입니다.
orders.customer_id은 customer.id의 값을 저장합니다 — 각 주문이 어떤 고객의 것인지 명시합니다.
참조 무결성이란 모든 외래 키 값이 실제 주 키와 일치해야 함을 의미합니다: 존재하지 않는 고객의 주문일 수 없습니다.
Common mistakes
- A PRIMARY KEY is unique and cannot be NULL.
- A foreign key points to another table's primary key.
흔한 실수
- PRIMARY KEY는 유니크하며 NULL일 수 없습니다.
- 외래 키는 다른 테이블의 주 키를 참조합니다.
Keys link two tables · 키가 두 테이블을 연결합니다
A shared key lets a row in one table point to a row in another. · 공유되는 키를 통해 한 테이블의 행이 다른 테이블의 행을 가리킬 수 있습니다.
Show the whole customer table so you can see the rows and their primary key id. · 전체 customer 테이블을 표시하여 행과 그 주 키 id를 볼 수 있게 하십시오.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
Show each order's id, its customer_id (the foreign key), and its total, ordered by id. · 각 주문의 id, 외래 키인 customer_id, 그리고 total를 표시하되, id으로 정렬하십시오.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.