Latihan 1: Relasi Antar Tabel — SQL

Latihan 1 dari materi Relasi Antar Tabel di SQL — praktek dengan editor kode interaktif, test case otomatis, dan hint terpandu. Langsung jalan di browser.

Database-nya sudah punya tabel customers (kolom id, name, email). Tulis CREATE TABLE orders yang terhubung ke tabel itu.

  1. id INTEGER PRIMARY KEY AUTOINCREMENT.
  2. customer_id INTEGER NOT NULL: id pelanggan pemilik pesanan.
  3. product TEXT NOT NULL.
  4. amount REAL.
  5. Di akhir daftar kolom: FOREIGN KEY (customer_id) REFERENCES customers(id).

Yang dinilai: tabel orders ada, keempat kolomnya punya tipe seperti di atas, id adalah INTEGER PRIMARY KEY AUTOINCREMENT, customer_id dan product sama-sama NOT NULL, dan customer_id punya foreign key ke tabel customers.

Hint