Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- insert_into
- Join
- sql
- Collections
- python
- SubqueryFilter
- python데이터베이스연동
- onetoone
- subquery
- 데이터베이스
- javascript
- sqlite3
- 몽고디비
- cursor()
- 파이썬
- 자바스크립트
- 밴쿠버응급실
- insertOne
- DATABASE
- statement
- MySQL
- PreparedStatement
- DBFilter
- PostgreSQL
- postgres
- DB
- 서브쿼리
- PostgresDB
- MongoDB
- query
Archives
- Today
- Total
새벽코딩
[PostgresDB-2] 8. Relationship ( 1:N, 1:1, M:N) & PK, FK 본문
Programming/Postgres DB
[PostgresDB-2] 8. Relationship ( 1:N, 1:1, M:N) & PK, FK
midnightcoder 2022. 12. 15. 14:27Relationship

1. One-to-Many / Many-to-one (1:N) relationship 일 대 다 관계
: 하나의 데이터가 여러개의 데이터를 포함하는 관계
e.g.
1)하나의 instagram 계정에 여러가지 사진들이 등록,
2)장바구니에 담긴 상품목록
3)하나의 기사에 달린 댓글들
4)팀에 속한 선수들



각 Recode의 대표값을 PK, 그리고 PK 가르키는 컬럼을 FK
이러한 PK와 FK의 연결을 통해서 데이터의 관계가 형성됨
**PK 와 FK 란?
- Primary Key : 레코드를 대표하는 값 일종의 identification ( == 주민등록번호)
: Representative (like SSN)
: Unique
: Named "id" (usually) - DB에 의해 자동생성됨

참고) 각 DB밴더에 맞게 작성하면됨

- Foreign Key
: 먼저 Column과 Type을 적은 다음에 해당 Column이 PK를 가르키도록 설정해줌 (Target PK)
user_id INTEGER RERFERENCES users(id)

출처 : 홍팍의 'SQL 데이터 분석, 활용!'
'Programming > Postgres DB' 카테고리의 다른 글
| [PostgresDB-2] 9. Relationship ( 1:1, M:N) 일대일, 다대다 (0) | 2022.12.21 |
|---|---|
| [PostgresDB-2] 8-2. Relationship ( 1:N) 실습 (0) | 2022.12.15 |
| [PostgresDB] 7. Timestamptz (0) | 2022.12.15 |
| [PostgresDB] 6. Aggregate Function (feat. SUM, AVG, MIN, MAX) (0) | 2022.12.15 |
| [PostgresDB] 5. 총점 및 평균 ( AS 사용) (0) | 2022.12.15 |