테이블과 열 만들기
Supabase에서 직접 새 테이블을 만들고 열 유형을 정의하며 기본 키를 설정하고 외래 키 제약 조건을 추가해 봅니다.
테이블과 열 만들기은(는) CoddyKit의 무료 Supabase Backend as a Service 강의입니다. 이것은 4개 중 2번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Supabase Backend as a Service 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Supabase Backend as a Service 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Building Blocks of Your Data
Welcome to creating your first database! Just like organizing information in a spreadsheet, databases use tables to hold related data.
Think of a table as a single sheet in your spreadsheet. Each table has columns, which are like the headings, defining what kind of information each entry will hold.
Into the Supabase Studio
Supabase provides a powerful web interface called the Supabase Studio (or Dashboard) to manage your project. This is where we'll create our tables.
- First, log in to your Supabase project.
- On the left sidebar, click the Database icon (it looks like a cylinder).
- Then, select Table Editor from the submenu.
Your First Table
Once in the Table Editor, you'll see an option to create a new table. Let's make one for 'products'.
- Click the '+ New Table' button.
- Give your table a descriptive name, like
products. - Keep the schema as
publicfor now. This is the default container for your tables. - Click 'Save' to create the empty table.
Adding Columns to Your Table
An empty table isn't very useful! Now, let's add some columns to our products table. Columns define the specific pieces of information each product will have.
- In the table editor, find your new
productstable. - Click '+ Add column'.
- You'll specify the column's name, data type, and other properties.
Choosing the Right Data Type
Each column needs a data type, which tells the database what kind of data it can store (text, numbers, dates, etc.).
text: For names, descriptions, or any string of characters.integer: For whole numbers (e.g., quantity).numericordecimal: For numbers with decimal points (e.g., price).boolean: For true/false values (e.g.,is_available).uuid: A universally unique identifier, great for primary keys.
Unique Identifiers: Primary Keys
Every table needs a Primary Key (PK). This is a special column (or set of columns) that uniquely identifies each row in the table. No two rows can have the same primary key value.
A common practice is to use a uuid (Universally Unique Identifier) as the primary key. Supabase can automatically generate these for you.
- When adding an
idcolumn, set its type touuid. - Check the 'Is Primary Key' box.
- Set the 'Default Value' to
gen_random_uuid(). This will auto-generate a unique ID for every new row.
Connecting Your Data: Foreign Keys
Databases are powerful because they can link related information across different tables. This is done using a Foreign Key (FK).
A foreign key in one table points to the primary key of another table. It establishes a relationship, ensuring data consistency. For example, a posts table might have a user_id foreign key linking to the id in the users table.
Practical Example: Users & Posts
Let's create two tables, users and posts, and link them using a foreign key. Run this SQL directly in the Supabase SQL Editor (accessible from the left sidebar).
CREATE TABLE users (
id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
username text NOT NULL UNIQUE,
email text NOT NULL UNIQUE
);
CREATE TABLE posts (
id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
user_id uuid REFERENCES users(id) ON DELETE CASCADE,
title text NOT NULL,
content text,
created_at timestamp WITH TIME ZONE DEFAULT now()
);Reviewing Your Database Structure
After running the SQL or creating tables via the UI, you can always review your database structure in the Supabase Studio.
- Go back to the Table Editor.
- You'll see your new tables listed.
- Click on a table name to see its columns, data types, and any primary or foreign key constraints.
- The 'Relationships' tab can also show how your tables are connected.
Test Your Knowledge
Which of the following statements about database tables and keys are TRUE?
Tables & Columns: Recap
Great job! In this lesson, you've learned the fundamental concepts of database structure:
- Tables are containers for related data.
- Columns define the specific attributes within a table.
- Data types specify the kind of data a column can hold.
- Primary Keys uniquely identify each row.
- Foreign Keys link tables together, defining relationships.
You now have the skills to start structuring your Supabase database effectively. Next, we'll learn how to put data into these tables!
자주 묻는 질문
“테이블과 열 만들기” 강의는 무료인가요?
네 — “테이블과 열 만들기” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Supabase Backend as a Service 강의 전체를 잠금 해제할 수 있습니다. Supabase Backend as a Service 강의에는 총 4개의 강의가 포함되어 있습니다.
“테이블과 열 만들기”에서 뭘 배우나요?
Supabase에서 직접 새 테이블을 만들고 열 유형을 정의하며 기본 키를 설정하고 외래 키 제약 조건을 추가해 봅니다. 브라우저에서 직접 실행하는 실습 코드로 Supabase Backend as a Service을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Supabase Backend as a Service을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Supabase Backend as a Service은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 2번째 강의입니다.
“테이블과 열 만들기” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Supabase Backend as a Service 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Supabase Backend as a Service 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- 데이터베이스 스키마 설계
- 테이블과 열 만들기
- 기본 데이터 삽입과 조회
- 관계와 외래 키