This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · Halaman ini memerlukan browser terbaru (dengan dukungan SharedArrayBuffer). Silakan perbarui Chrome, Edge, Firefox, atau Safari ke versi terbaru.
A database 数据库 keeps data in tables 表. A query 查询 reads data with SELECT. SELECT * returns every column; FROM names the table.
Each row 行 is one record 记录. SQL keywords are written in UPPERCASE by habit.
A statement ends with a semicolon ;.
Bahasa Indonesia
Database menyimpan data dalam tabel. Query membaca data dengan SELECT. SELECT * mengembalikan semua kolom; FROM menamai tabel.
CREATE TABLE student (id INTEGER, name TEXT, score INTEGER);
INSERT INTO student VALUES (1, 'Mei', 88), (2, 'Sam', 71);
SELECT * FROM student;
Tabel menyimpan rekaman: setiap baris adalah satu rekaman, setiap kolom adalah satu bidang
Setiap baris adalah satu rekaman. Kata kunci SQL ditulis dengan HURUF BESAR karena kebiasaan.
Pernyataan diakhiri dengan titik koma ;.
1.2
Memilih kolom
English
List the columns 列 you want, separated by commas. Use AS to rename a column in the result (an alias 别名).
A selected column can also be a calculation — pair it with AS to name the new column:
SELECT DISTINCT col removes duplicate values from the result.
Bahasa Indonesia
Daftarkan kolom yang Anda inginkan, pisahkan dengan koma. Gunakan AS untuk memberi nama ulang kolom dalam hasil (alias).
CREATE TABLE student (id INTEGER, name TEXT, score INTEGER);
INSERT INTO student VALUES (1, 'Mei', 88), (2, 'Sam', 71);
SELECT name, score AS mark FROM student;
Kolom yang dipilih juga bisa berupa perhitungan — padankan dengan AS untuk menamai kolom baru:
CREATE TABLE student (id INTEGER, name TEXT, score INTEGER);
INSERT INTO student VALUES (1, 'Mei', 88), (2, 'Sam', 71);
SELECT name, score + 5 AS bonus FROM student;
SELECT DISTINCT col menghapus nilai duplikat dari hasil.
1.3
Memfilter dengan WHERE
English
WHERE keeps only the rows that match a condition 条件. Compare with =, <> (not equal), <, >, <=, >=. Put text in single quotes.
SQL runs the parts in this order: FROM → WHERE → SELECT.
Common mistakes
Put text values in single quotes: WHERE name = 'Ann'; column names have no quotes.
SELECT * returns every column — name only the columns you need.
WHERE filters rows; it comes after FROM.
Bahasa Indonesia
WHERE hanya menyimpan baris yang sesuai dengan kondisi. Bandingkan dengan =, <> (tidak sama), <, >, <=, >=. Masukkan teks dalam tanda petik tunggal.
CREATE TABLE student (id INTEGER, name TEXT, score INTEGER);
INSERT INTO student VALUES (1, 'Mei', 88), (2, 'Sam', 71), (3, 'Ana', 95);
SELECT name, score FROM student WHERE score >= 80;
SQL menjalankan bagian-bagian ini dalam urutan: FROM → WHERE → SELECT.
Kesalahan umum
Letakkan nilai teks dalam kutipan tunggal: WHERE name = 'Ann'; nama kolom tanpa tanda kutip.
SELECT * mengembalikan semua kolom — beri nama hanya kolom yang Anda butuhkan.
Combine conditions with AND, OR, NOT. AND needs all sides true; OR needs any side true; NOT reverses one. Use brackets to set the precedence 优先级.
Bahasa Indonesia
Gabungkan kondisi dengan AND, OR, NOT. AND memerlukan semua sisi benar; OR memerlukan salah satu sisi benar; NOT membalik satu sisi. Gunakan kurung untuk menetapkan prioritas.
CREATE TABLE student (id INTEGER, name TEXT, form TEXT, score INTEGER);
INSERT INTO student VALUES (1,'Mei','11A',88),(2,'Sam','11B',71),(3,'Ana','11A',95);
SELECT name FROM student WHERE form = '11A' AND score >= 90;
AND memerlukan semua benar; OR memerlukan salah satu; NOT membalik satu
2.2
LIKE, IN dan BETWEEN
English
LIKE matches a text pattern 模式: % stands for any text and _ for one character — these are wildcards 通配符.
Pattern
Matches
'M%'
starts with M
'%a'
ends with a
'%an%'
contains "an"
'M_i'
M, then exactly one character, then i
IN matches a set 集合 of values; BETWEEN matches a range 范围 (both ends included).
Bahasa Indonesia
LIKE mencocokkan pola teks: % mewakili teks apa pun dan _ untuk satu karakter — ini adalah karakter buangan.
CREATE TABLE student (id INTEGER, name TEXT, form TEXT, score INTEGER);
INSERT INTO student VALUES (1,'Mei','11A',88),(2,'Sam','11B',71),(3,'Ana','11A',95);
SELECT name FROM student WHERE name LIKE 'M%'; -- starts with M
Pola
Mencocokkan
'M%'
dimulai dengan M
'%a'
diakhiri dengan a
'%an%'
mengandung "an"
'M_i'
M, kemudian tepat satu karakter, kemudian i
IN mencocokkan sekumpulan nilai; BETWEEN mencocokkan rentang (kedua ujung termasuk).
CREATE TABLE student (id INTEGER, name TEXT, form TEXT, score INTEGER);
INSERT INTO student VALUES (1,'Mei','11A',88),(2,'Sam','11B',71),(3,'Ana','11A',95);
SELECT name, score FROM student
WHERE form IN ('11A', '11C') AND score BETWEEN 80 AND 100;
2.3
NULL
English
NULL marks a missing value 缺失值 — nothing was stored in that cell. NULL is not 0 and not an empty string. A comparison with = or <> never matches it; test with IS NULL or IS NOT NULL.
WHERE score = NULL returns no rows at all — not even Sam's row.
A NULL in arithmetic gives NULL: score + 5 stays NULL for Sam.
Common mistakes
Test for an empty value with IS NULL, never = NULL.
In LIKE, % matches any text and _ matches one character: 'A%' means "starts with A".
IN (1, 2, 3) is shorter than many ORs; BETWEEN a AND b includes both ends.
Bahasa Indonesia
NULL menandai nilai yang hilang — tidak ada yang disimpan di sel tersebut. NULL bukan 0 dan bukan string kosong. Perbandingan dengan = atau <> tidak akan cocok dengannya; uji dengan IS NULL atau IS NOT NULL.
CREATE TABLE student (id INTEGER, name TEXT, score INTEGER);
INSERT INTO student VALUES (1, 'Mei', 88), (2, 'Sam', NULL), (3, 'Ana', 95);
SELECT name FROM student WHERE score IS NULL;
CREATE TABLE student (id INTEGER, name TEXT, score INTEGER);
INSERT INTO student VALUES (1, 'Mei', 88), (2, 'Sam', NULL), (3, 'Ana', 95);
SELECT name, score FROM student WHERE score IS NOT NULL;
WHERE score = NULL tidak mengembalikan baris sama sekali — bahkan tidak baris Sam.
NULL dalam aritmatika menghasilkan NULL: score + 5 tetap NULL untuk Sam.
Kesalahan umum
Uji nilai kosong dengan IS NULL, jangan gunakan = NULL.
Dalam LIKE, % mencocokkan teks apa pun dan _ mencocokkan satu karakter: 'A%' berarti "dimulai dengan A".
IN (1, 2, 3) lebih pendek dari banyak ORs; BETWEEN a AND b mencakup kedua ujungnya.
ORDER BY sorts 排序 the result rows. Add DESC for descending 降序 (high to low); the default is ascending 升序 (low to high).
Sort by more than one column
List several columns. A tie 平局 in the first column is broken by the next.
LIMIT (top-N)
LIMIT n keeps only the first n rows — pair it with ORDER BY for a top-N 前 N 名 list.
ORDER BY can also sort by an alias or a calculation: ORDER BY avg_score DESC.
Text sorts alphabetically: ORDER BY name runs A → Z.
Common mistakes
ORDER BY sorts ascending by default; add DESC for descending.
ORDER BY comes near the end, after WHERE and GROUP BY.
LIMIT caps how many rows come back, but only after sorting.
Bahasa Indonesia
ORDER BY mengurutkan baris hasil. Tambahkan DESC untuk urutan menurun (tinggi ke rendah); defaultnya adalah urutan menaik (rendah ke tinggi).
CREATE TABLE student (id INTEGER, name TEXT, score INTEGER);
INSERT INTO student VALUES (1,'Mei',88),(2,'Sam',71),(3,'Ana',95);
SELECT name, score FROM student ORDER BY score DESC;
Urutkan berdasarkan lebih dari satu kolom
Daftarkan beberapa kolom. Kekurangan pada kolom pertama diselesaikan oleh kolom berikutnya.
CREATE TABLE student (id INTEGER, name TEXT, score INTEGER);
INSERT INTO student VALUES (1,'Mei',88),(2,'Sam',88),(3,'Ana',95);
SELECT name, score FROM student ORDER BY score DESC, name ASC;
LIMIT (top-N)
LIMIT n hanya mempertahankan n baris pertama — padangkan dengan ORDER BY untuk daftar top-N.
CREATE TABLE student (id INTEGER, name TEXT, score INTEGER);
INSERT INTO student VALUES (1,'Mei',88),(2,'Sam',71),(3,'Ana',95);
SELECT name, score FROM student ORDER BY score DESC LIMIT 2;
ORDER BY juga dapat mengurutkan berdasarkan alias atau perhitungan: ORDER BY avg_score DESC.
Teks diurutkan secara alfabetis: ORDER BY name menjalankan A → Z.
Kesalahan umum
ORDER BY mengurutkan menaik secara default; tambahkan DESC untuk urutan menurun.
ORDER BY berada di akhir, setelah WHERE dan GROUP BY.
LIMIT membatasi berapa banyak baris yang dikembalikan, tetapi hanya setelah pengurutan.
ORDER BY mengurutkan; LIMIT mempertahankan n baris pertama setelah pengurutan
An aggregate function 聚合函数 turns many rows into one summary 汇总 value. Wrap an average in ROUND(x, 2) to tidy it.
Function
Gives
COUNT(*)
how many rows
SUM(col)
the total
AVG(col)
the mean average
MIN(col) / MAX(col)
the smallest / largest value
Bahasa Indonesia
Fungsi agregat mengubah banyak baris menjadi satu nilai ringkasan. Bungkus rata-rata dalam ROUND(x, 2) agar rapi.
Fungsi
Memberikan
COUNT(*)
berapa banyak baris
SUM(col)
total
AVG(col)
rata-rata aritmatika
MIN(col) / MAX(col)
nilai terkecil / terbesar
CREATE TABLE student (id INTEGER, name TEXT, form TEXT, score INTEGER);
INSERT INTO student VALUES (1,'Mei','11A',88),(2,'Sam','11B',71),(3,'Ana','11A',95);
SELECT COUNT(*), ROUND(AVG(score), 2), MAX(score) FROM student;
4.2
GROUP BY dan HAVING
English
GROUP BY makes one summary row per group 组. HAVING filters those groups — it is like WHERE, but it runs after grouping.
Whatever order you write them in, SQL always runs the clauses of a query in the same fixed order:
Step
Clause
1
FROM (and any JOIN)
2
WHERE — filter rows
3
GROUP BY — form groups
4
HAVING — filter groups
5
SELECT — compute the output columns
6
ORDER BY, then LIMIT
Common mistakes
You cannot select a plain column beside an aggregate unless it is in GROUP BY.
Filter rows with WHERE (before grouping) and filter groups with HAVING (after).
COUNT(*) counts rows; COUNT(col) skips NULLs in that column.
Bahasa Indonesia
GROUP BY membuat satu baris ringkasan per kelompok. HAVING memfilter kelompok-kelompok tersebut — ini seperti WHERE, tetapi berjalan setelah pengelompokan.
CREATE TABLE student (id INTEGER, name TEXT, form TEXT, score INTEGER);
INSERT INTO student VALUES (1,'Mei','11A',88),(2,'Sam','11B',71),(3,'Ana','11A',95);
SELECT form, COUNT(*) AS n, ROUND(AVG(score), 2) AS avg_score
FROM student
GROUP BY form
HAVING COUNT(*) > 1;
GROUP BY mengumpulkan baris ke dalam satu keranjang per nilai; setiap keranjang menjadi satu baris ringkasan
Terlepas dari urutan penulisan, SQL selalu menjalankan klausa query dalam urutan tetap yang sama:
Tahap
Klausa
1
FROM (dan setiap JOIN)
2
WHERE — filter baris
3
GROUP BY — buat kelompok
4
HAVING — filter kelompok
5
SELECT — hitung kolom output
6
ORDER BY, lalu LIMIT
Kesalahan umum
Anda tidak dapat memilih kolom biasa di samping agregat kecuali berada dalam GROUP BY.
Filter baris dengan WHERE (sebelum pengelompokan) dan filter kelompok dengan HAVING (setelah).
COUNT(*) menghitung baris; COUNT(col) melewatkan NULL pada kolom tersebut.
A primary key 主键 uniquely names each row in a table. A foreign key 外键 in one table points to the primary key of another — that builds a relationship 关系 between them.
Bahasa Indonesia
Kunci primer memberikan nama unik untuk setiap baris dalam tabel. Kunci asing di satu tabel menunjuk ke kunci primer tabel lain — hal itu membangun hubungan di antara keduanya.
CREATE TABLE class (id INTEGER, name TEXT);
CREATE TABLE student (id INTEGER, name TEXT, class_id INTEGER);
INSERT INTO class VALUES (1, 'Maths'), (2, 'Art');
INSERT INTO student VALUES (1, 'Mei', 1), (2, 'Sam', 2);
SELECT * FROM student;
5.2
INNER JOIN
English
A join 连接 combines rows from two tables. INNER JOIN ... ON ... keeps rows where the keys match. A short alias 别名 (s, c) keeps the query readable.
Bahasa Indonesia
Join menggabungkan baris dari dua tabel. INNER JOIN ... ON ... menyimpan baris di mana kuncinya cocok. Alias pendek (s, c) menjaga query tetap mudah dibaca.
CREATE TABLE class (id INTEGER, name TEXT);
CREATE TABLE student (id INTEGER, name TEXT, class_id INTEGER);
INSERT INTO class VALUES (1, 'Maths'), (2, 'Art');
INSERT INTO student VALUES (1, 'Mei', 1), (2, 'Sam', 2);
SELECT s.name, c.name AS class
FROM student s INNER JOIN class c ON s.class_id = c.id;
INNER JOIN mencocokkan setiap kunci asing dengan kunci primer dan menggabungkan baris yang cocok
5.3
Menggabungkan dengan pengelompokan
English
Join first, then GROUP BY to summarise across the joined rows.
Bahasa Indonesia
Gabungkan terlebih dahulu, lalu GROUP BY untuk merangkum melintasi baris yang digabungkan.
CREATE TABLE class (id INTEGER, name TEXT);
CREATE TABLE student (id INTEGER, name TEXT, class_id INTEGER);
INSERT INTO class VALUES (1, 'Maths'), (2, 'Art');
INSERT INTO student VALUES (1, 'Mei', 1), (2, 'Sam', 2), (3, 'Ana', 1);
SELECT c.name AS class, COUNT(*) AS n
FROM student s INNER JOIN class c ON s.class_id = c.id
GROUP BY c.name;
5.4
LEFT JOIN
English
An INNER JOIN keeps only matched rows. A LEFT JOIN 左连接 keeps every row of the left (first) table; where there is no match, the right table's columns come back as NULL.
Sam has no class, but the row still appears — with class as NULL.
To find only the unmatched rows, add WHERE c.id IS NULL.
Common mistakes
A join with no ON condition pairs every row with every row (a cross join).
Match the foreign key to the primary key: ON orders.customer_id = customers.id.
An INNER JOIN drops rows that have no match on the other side; use a LEFT JOIN to keep them.
Bahasa Indonesia
Sebuah INNER JOIN hanya menyimpan baris yang cocok. Sebuah LEFT JOIN menyimpan semua baris dari tabel kiri (pertama); di mana tidak ada kecocokan, kolom tabel kanan kembali sebagai NULL.
CREATE TABLE class (id INTEGER, name TEXT);
CREATE TABLE student (id INTEGER, name TEXT, class_id INTEGER);
INSERT INTO class VALUES (1, 'Maths'), (2, 'Art');
INSERT INTO student VALUES (1, 'Mei', 1), (2, 'Sam', NULL);
SELECT s.name, c.name AS class
FROM student s LEFT JOIN class c ON s.class_id = c.id;
Sam tidak memiliki kelas, tetapi baris tetap muncul — dengan class sebagai NULL.
Untuk menemukan hanya baris yang tidak cocok, tambahkan WHERE c.id IS NULL.
Kesalahan umum
Join tanpa ON kondisi memasangkan setiap baris dengan setiap baris (cross join).
Cocokkan kunci asing dengan kunci primer: ON orders.customer_id = customers.id.
INNER JOIN membuang baris yang tidak memiliki kecocokan di sisi lain; gunakan LEFT JOIN untuk menyimpannya.
INSERT INTO ... VALUES ... adds new rows 行. Name the columns, then give the values in the same order. (Each block below ends with a SELECT so you can see the result.)
INSERT INTO t VALUES (...), (...); adds several rows in one statement.
Bahasa Indonesia
INSERT INTO ... VALUES ... menambahkan baris baru. Beri nama kolom, lalu berikan nilai dalam urutan yang sama. (Setiap blok di bawah ini diakhiri dengan sebuah SELECT agar Anda dapat melihat hasilnya.)
CREATE TABLE student (id INTEGER, name TEXT, score INTEGER);
INSERT INTO student (id, name, score) VALUES (1, 'Mei', 88);
INSERT INTO student VALUES (2, 'Sam', 71);
SELECT * FROM student;
INSERT INTO t VALUES (...), (...); menambahkan beberapa baris dalam satu pernyataan.
INSERT menambahkan baris baru ke tabel
6.2
UPDATE
English
UPDATE ... SET ... WHERE ... changes existing rows. Always add WHERE, or every row changes.
Bahasa Indonesia
UPDATE ... SET ... WHERE ... mengubah baris yang sudah ada. Selalu tambahkan WHERE, atau semua baris berubah.
CREATE TABLE student (id INTEGER, name TEXT, score INTEGER);
INSERT INTO student VALUES (1, 'Mei', 88), (2, 'Sam', 71);
UPDATE student SET score = 75 WHERE name = 'Sam';
SELECT * FROM student;
6.3
DELETE
English
DELETE FROM ... WHERE ... removes rows. Without WHERE it empties the whole table 表.
Common mistakes
UPDATE and DELETEwithout a WHERE change every row — always add the WHERE.
In INSERT, the values must line up with the column list in order and type.
Test a risky DELETE first as a SELECT with the same WHERE.
Bahasa Indonesia
DELETE FROM ... WHERE ... menghapus baris. Tanpa WHERE itu akan mengosongkan seluruh tabel.
CREATE TABLE student (id INTEGER, name TEXT, score INTEGER);
INSERT INTO student VALUES (1, 'Mei', 88), (2, 'Sam', 71);
DELETE FROM student WHERE score < 80;
SELECT * FROM student;
Kesalahan umum
UPDATE dan DELETEtanpa sebuah WHERE mengubah setiap baris — selalu tambahkan WHERE.
Dalam INSERT, nilainya harus sejajar dengan daftar kolom secara berurutan dan bertipe.
Uji DELETE yang berisiko terlebih dahulu sebagai SELECT dengan WHERE yang sama.
CREATE TABLE defines a table's schema 表结构: the column names and their data types 数据类型. The main SQLite types are INTEGER, TEXT, and REAL (a decimal number).
Bahasa Indonesia
CREATE TABLE mendefinisikan skema tabel: nama kolom dan tipe datanya. Tipe SQLite utama adalah INTEGER, TEXT, dan REAL (angka desimal).
CREATE TABLE student (id INTEGER, name TEXT, score REAL);
INSERT INTO student VALUES (1, 'Mei', 88.5);
SELECT * FROM student;
CREATE TABLE memberi nama kolom dan tipenya
7.2
Kunci & batasan
English
A constraint 约束 is a rule on a column: PRIMARY KEY (a unique id), NOT NULL (must have a value), UNIQUE, and DEFAULT (a fallback value).
Declare a foreign key with REFERENCES — it records that the column points at another table's primary key:
The long form is FOREIGN KEY (class_id) REFERENCES class(id) on its own line.
Bahasa Indonesia
Batasan adalah aturan pada kolom: PRIMARY KEY (id unik), NOT NULL (harus memiliki nilai), UNIQUE, dan DEFAULT (nilai cadangan).
CREATE TABLE student (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
score INTEGER DEFAULT 0
);
INSERT INTO student (id, name) VALUES (1, 'Mei');
SELECT * FROM student;
Deklarasikan kunci asing dengan REFERENCES — ia mencatat bahwa kolom tersebut menunjuk ke kunci primer tabel lain:
CREATE TABLE class (id INTEGER PRIMARY KEY, name TEXT);
CREATE TABLE student (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
class_id INTEGER REFERENCES class(id)
);
INSERT INTO class VALUES (1, 'Maths');
INSERT INTO student VALUES (1, 'Mei', 1);
SELECT s.name, c.name AS class
FROM student s INNER JOIN class c ON s.class_id = c.id;
Bentuk panjangnya adalah FOREIGN KEY (class_id) REFERENCES class(id) pada baris sendiri.
7.3
ALTER TABLE
English
ALTER TABLE ... ADD COLUMN ... changes the schema of a table that already exists. A DEFAULT fills the new column in the old rows.
ALTER TABLE student RENAME TO pupil; renames the whole table.
DROP TABLE student; deletes the table completely — structure and data.
Common mistakes
Every column needs a data type (e.g. INTEGER, TEXT).
A PRIMARY KEY must be unique and cannot be NULL.
A foreign key value must exist in the table it points to.
Bahasa Indonesia
ALTER TABLE ... ADD COLUMN ... mengubah skema tabel yang sudah ada. Sebuah DEFAULT mengisi kolom baru di baris lama.
CREATE TABLE student (id INTEGER, name TEXT);
INSERT INTO student VALUES (1, 'Mei');
ALTER TABLE student ADD COLUMN score INTEGER DEFAULT 0;
SELECT * FROM student;
ALTER TABLE student RENAME TO pupil; mengganti nama seluruh tabel.
DROP TABLE student; menghapus tabel sepenuhnya — struktur dan data.
Kesalahan umum
Setiap kolom membutuhkan tipe data (misalnya INTEGER, TEXT).
Tables connect through relationships 关系. One-to-many 一对多 is the most common: one class has many students. Many-to-many 多对多 needs a join table 连接表 in the middle. An entity-relationship diagram 实体关系图 (ER diagram) draws each entity 实体 as a box and each relationship as a line.
Relationship
Example
one-to-one
a person and their passport
one-to-many
a class and its students
many-to-many
students and clubs
The join table holds one row per link. Here Mei is in two clubs, and Chess has two members:
Bahasa Indonesia
Tabel terhubung melalui hubungan. Satu-ke-banyak adalah yang paling umum: satu kelas memiliki banyak siswa. Banyak-ke-banyak memerlukan tabel join di tengah. Diagram entitas-relasi (ER diagram) menggambar setiap entitas sebagai kotak dan setiap hubungan sebagai garis.
Hubungan
Contoh
satu-ke-satu
seseorang dan paspornya
satu-ke-banyak
sebuah kelas dan siswanya
banyak-ke-banyak
siswa dan klub
Sisi "banyak" membawa kunci asing; tautan banyak-ke-banyak memerlukan tabel join
Tabel join memegang satu baris per tautan. Di sini Mei ada di dua klub, dan Chess memiliki dua anggota:
CREATE TABLE student (id INTEGER PRIMARY KEY, name TEXT);
CREATE TABLE club (id INTEGER PRIMARY KEY, name TEXT);
CREATE TABLE membership (student_id INTEGER, club_id INTEGER);
INSERT INTO student VALUES (1, 'Mei'), (2, 'Sam');
INSERT INTO club VALUES (1, 'Chess'), (2, 'Art');
INSERT INTO membership VALUES (1, 1), (1, 2), (2, 1);
SELECT s.name, c.name AS club
FROM membership m
INNER JOIN student s ON m.student_id = s.id
INNER JOIN club c ON m.club_id = c.id;
8.2
Normalisasi
English
Normalisation 范式化 organises tables to avoid redundancy 冗余 (the same data repeated) and the update mistakes it causes. The first three normal forms 范式:
1NF: every cell holds one atomic 原子 value — no lists inside a cell.
2NF: no column depends on only part of a composite key 复合主键.
3NF: no column depends on another non-key column.
Unnormalised (bad)
Normalised (better)
student(name, club1, club2)
student(name) + membership(student, club)
Common mistakes
Split repeating groups into their own table (normalisation) instead of many similar columns.
Each table should describe ONE kind of thing.
Link tables with a foreign key that points to another table's primary key.
Bahasa Indonesia
Normalisasi mengatur tabel untuk menghindari redundansi (data yang sama berulang) dan kesalahan pembaruan yang ditimbulkannya. Tiga bentuk normalisasi pertama:
1NF: setiap sel memegang satu nilai atomik — tidak ada daftar di dalam sel.
2NF: tidak ada kolom yang bergantung hanya pada sebagian dari kunci komposit.
3NF: tidak ada kolom yang bergantung pada kolom non-kunci lainnya.
Tidak dinormalisasi (buruk)
Dinormalisasi (lebih baik)
student(name, club1, club2)
student(name) + membership(student, club)
Kesalahan umum
Pisahkan grup berulang menjadi tabel tersendiri (normalisasi) alih-alih banyak kolom serupa.
Setiap tabel harus menggambarkan SATU jenis sesuatu.
Hubungkan tabel dengan kunci asing yang menunjuk ke kunci primer tabel lain.
Pick one and the site follows you — notes, papers, videos and practice all open on it. · Pilih satu dan situs mengikuti Anda — catatan, kertas, video, dan latihan semua terbuka di sana.
Type to search notes, lessons, code, vocabulary and past-paper questions across every subject. · Ketik untuk mencari catatan, pelajaran, kode, kosakata, dan pertanyaan soal lama di setiap mata pelajaran.