ควิซ SQL: Constraints & Keys

This SQL quiz tests the constraints that keep bad data out of your tables. You will decide which inserts and deletes fail, how primary and foreign keys behave, and where SQLite, MySQL and PostgreSQL disagree.

ปานกลาง 10 ข้อ ~6 นาที ผ่านที่ 80% SQLite

เลือกโหมด

กำลังเล่นแบบผู้เยี่ยมชม: เข้าสู่ระบบเพื่อเก็บ XP และ streak

ตัวอย่างคำถาม

ข้อ 1 จาก 10

What happens when this runs?

CREATE TABLE users (id INTEGER PRIMARY KEY, email TEXT NOT NULL);
INSERT INTO users (id) VALUES (1);
SELECT COUNT(*) FROM users;
ดูเฉลย

A. Error email has no default, so leaving it out would store NULL, which NOT NULL rejects. The insert fails with a constraint error instead of quietly saving an empty email.

ควิซนี้มีเนื้อหาอะไรบ้าง

  • NOT NULL, UNIQUE and CHECK constraints
  • Primary keys, composite keys and auto-generated ids
  • Foreign keys and ON DELETE CASCADE
  • Upserts with ON CONFLICT ... DO UPDATE
  • Engine differences, like SQLite's foreign key switch

คำถามที่พบบ่อย

ต้องมีบัญชีไหม?

ไม่ต้อง ใครก็เล่นได้ เข้าสู่ระบบเพื่อเก็บ XP, streak, เหรียญตรา และประวัติ

ทำซ้ำได้ไหม?

ได้ ระบบเก็บคะแนนที่ดีที่สุดไว้ และสลับคำถามกับตัวเลือกใหม่ทุกครั้ง