데이터베이스 스키마 설계
확장성과 효율성을 고려해 데이터를 구조화하고 관계를 정의하며 데이터베이스 테이블을 계획하는 모범 사례를 배웁니다.
데이터베이스 스키마 설계은(는) CoddyKit의 무료 Supabase Backend as a Service 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Supabase Backend as a Service 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Supabase Backend as a Service 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
What's a Database Schema?
Imagine building a house. Before you lay a single brick, you need a blueprint! In databases, that blueprint is called a schema.
A database schema defines the structure of your data. It tells you:
- What tables exist
- What columns each table has
- How different tables are connected
A good schema is key for a well-organized, efficient, and scalable Supabase project.
Identify Entities & Attributes
First, think about the 'things' you want to store. These are your entities. For a social app, entities might be Users, Posts, or Comments.
Next, what details does each entity have? These are its attributes.
- User: name, email, profile picture URL
- Post: title, content, creation date
Listing these helps you imagine your tables.
Primary Keys: Your Unique ID
Every entity needs a way to be uniquely identified. That's where a Primary Key comes in!
A primary key is a column (or set of columns) that contains a unique value for each row in a table. Think of it like a student ID number – no two students have the same one.
The most common primary key is an id column, often an auto-incrementing integer or a UUID (Universally Unique Identifier).
How Data Connects: Relationships
Your entities don't live in isolation; they interact! These interactions are called relationships.
The most common type is One-to-Many. For example:
- One User can write Many Posts.
- One Album can have Many Songs.
Understanding these connections is crucial for linking your tables.
Foreign Keys: Building Connections
To establish a One-to-Many relationship, we use a Foreign Key.
A foreign key is a column in one table that refers to the primary key in another table. It's how we say, 'This post belongs to this specific user.'
If a posts table needs to know which user created it, the posts table would have a user_id column that points to the id of a row in the users table.
Data Types: Store Smartly
When defining your columns, you need to pick a data type. This tells the database what kind of information that column will hold (text, numbers, dates, etc.).
Common PostgreSQL (Supabase's database) data types include:
text: For names, descriptionsinteger: For whole numbers (e.g., age, count)boolean: For true/false values (e.g.,is_active)timestamp: For dates and times (e.g.,created_at)
Choosing the right type saves space and improves performance.
Normalization: Tidy Your Data
Normalization is a process to organize your database to reduce data redundancy and improve data integrity.
Imagine if every post stored the user's full name and email. If the user changes their email, you'd have to update it in many places! Normalization helps avoid this.
By splitting data into separate, related tables (e.g., users and posts), you store common information only once.
Denormalization: For Speed
While normalization is great for data integrity, sometimes it can slow down data retrieval because you need to 'join' many tables.
Denormalization is the intentional introduction of redundancy to improve read performance. For example, storing a user's name directly in a posts table, even though it's also in the users table.
This is a trade-off: faster reads, but more complex updates and potential for inconsistencies. Use it wisely!
Design in Action: Users & Tasks
Let's design a simple schema for users and their to-do tasks. Each user can have many tasks.
Here's how we might define the tables based on our design principles:
CREATE TABLE users (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name TEXT NOT NULL,
email TEXT UNIQUE NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
CREATE TABLE tasks (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID REFERENCES users(id) ON DELETE CASCADE,
title TEXT NOT NULL,
description TEXT,
is_complete BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);Quick Check: Design Concepts
You're planning a database for a blog. You need to store Authors and their Articles. Each author can write many articles.
Which of these statements correctly apply good schema design principles for this scenario?
Recap: Your Design Journey
You've just taken your first steps into database schema design!
We covered:
- Identifying entities and attributes
- The role of primary and foreign keys
- Understanding relationships (especially One-to-Many)
- The importance of selecting proper data types
- Briefly touching on normalization and denormalization
A well-designed schema is the foundation of any robust application. In the next lesson, we'll put this knowledge into practice by creating tables!
자주 묻는 질문
“데이터베이스 스키마 설계” 강의는 무료인가요?
네 — “데이터베이스 스키마 설계” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Supabase Backend as a Service 강의 전체를 잠금 해제할 수 있습니다. Supabase Backend as a Service 강의에는 총 4개의 강의가 포함되어 있습니다.
“데이터베이스 스키마 설계”에서 뭘 배우나요?
확장성과 효율성을 고려해 데이터를 구조화하고 관계를 정의하며 데이터베이스 테이블을 계획하는 모범 사례를 배웁니다. 브라우저에서 직접 실행하는 실습 코드로 Supabase Backend as a Service을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Supabase Backend as a Service을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Supabase Backend as a Service은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.
“데이터베이스 스키마 설계” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Supabase Backend as a Service 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Supabase Backend as a Service 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- 데이터베이스 스키마 설계
- 테이블과 열 만들기
- 기본 데이터 삽입과 조회
- 관계와 외래 키