Templates/Education

Quizzes & assessments database schema

Quizzes of multiple-choice questions, attempts and recorded answers.

6 tables, 7 relationships

Opens as a new diagram you can change. Free.

Tables

quizzes

  • iduuid not null
  • titletext not null
  • time_limit_minutesinteger
  • created_attimestamptz not null

questions

  • iduuid not null
  • quiz_id> quizzesuuid not null
  • prompttext not null
  • positioninteger not null
  • pointsinteger not null
  • created_attimestamptz not null

choices

  • iduuid not null
  • question_id> questionsuuid not null
  • labeltext not null
  • correctboolean not null
  • created_attimestamptz not null

takers

  • iduuid not null
  • emailtext not null
  • created_attimestamptz not null

attempts

  • iduuid not null
  • quiz_id> quizzesuuid not null
  • taker_id> takersuuid not null
  • started_attimestamptz not null
  • scoreinteger
  • created_attimestamptz not null

attempt_answers

  • iduuid not null
  • attempt_id> attemptsuuid not null
  • question_id> questionsuuid not null
  • choice_id> choicesuuid
  • created_attimestamptz not null

As PostgreSQL

The same diagram exports to MySQL, MariaDB, SQLite, SQL Server and Oracle, and to Prisma, Drizzle, SQLAlchemy and Convex models.

CREATE TABLE "attempt_answers" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "attempt_id" UUID NOT NULL,
  "question_id" UUID NOT NULL,
  "choice_id" UUID,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "attempts" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "quiz_id" UUID NOT NULL,
  "taker_id" UUID NOT NULL,
  "started_at" TIMESTAMPTZ NOT NULL,
  "score" INTEGER,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "choices" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "question_id" UUID NOT NULL,
  "label" TEXT NOT NULL,
  "correct" BOOLEAN DEFAULT false NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "questions" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "quiz_id" UUID NOT NULL,
  "prompt" TEXT NOT NULL,
  "position" INTEGER NOT NULL,
  "points" INTEGER DEFAULT 1 NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "quizzes" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "title" TEXT NOT NULL,
  "time_limit_minutes" INTEGER,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "takers" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "email" TEXT NOT NULL UNIQUE,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

ALTER TABLE "questions" ADD CONSTRAINT "fk_questions_quiz_id" FOREIGN KEY ("quiz_id") REFERENCES "quizzes" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "choices" ADD CONSTRAINT "fk_choices_question_id" FOREIGN KEY ("question_id") REFERENCES "questions" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "attempts" ADD CONSTRAINT "fk_attempts_quiz_id" FOREIGN KEY ("quiz_id") REFERENCES "quizzes" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "attempts" ADD CONSTRAINT "fk_attempts_taker_id" FOREIGN KEY ("taker_id") REFERENCES "takers" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "attempt_answers" ADD CONSTRAINT "fk_attempt_answers_attempt_id" FOREIGN KEY ("attempt_id") REFERENCES "attempts" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "attempt_answers" ADD CONSTRAINT "fk_attempt_answers_question_id" FOREIGN KEY ("question_id") REFERENCES "questions" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "attempt_answers" ADD CONSTRAINT "fk_attempt_answers_choice_id" FOREIGN KEY ("choice_id") REFERENCES "choices" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

More Education templates

Start with one diagram, free

One diagram with two branches, no card needed. Upgrade when your team needs more.