Templates/Education

Library database schema

Books with authors, physical copies, members, loans and holds.

7 tables, 7 relationships

Opens as a new diagram you can change. Free.

Tables

authors

  • iduuid not null
  • full_nametext not null
  • created_attimestamptz not null

books

  • iduuid not null
  • titletext not null
  • isbntext not null
  • published_yearinteger
  • created_attimestamptz not null

book_authors

  • iduuid not null
  • book_id> booksuuid not null
  • author_id> authorsuuid not null
  • created_attimestamptz not null

copies

  • iduuid not null
  • book_id> booksuuid not null
  • barcodetext not null
  • conditiontext not null
  • created_attimestamptz not null

library_members

  • iduuid not null
  • full_nametext not null
  • card_numbertext not null
  • created_attimestamptz not null

loans

  • iduuid not null
  • copy_id> copiesuuid not null
  • member_id> library_membersuuid not null
  • due_ondate not null
  • returned_ondate
  • created_attimestamptz not null

holds

  • iduuid not null
  • book_id> booksuuid not null
  • member_id> library_membersuuid not null
  • fulfilled_attimestamptz
  • 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 "authors" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "full_name" TEXT NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "book_authors" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "book_id" UUID NOT NULL,
  "author_id" UUID NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "books" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "title" TEXT NOT NULL,
  "isbn" TEXT NOT NULL UNIQUE,
  "published_year" INTEGER,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "copies" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "book_id" UUID NOT NULL,
  "barcode" TEXT NOT NULL UNIQUE,
  "condition" TEXT DEFAULT 'good' NOT NULL,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

CREATE TABLE "holds" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "book_id" UUID NOT NULL,
  "member_id" UUID NOT NULL,
  "fulfilled_at" TIMESTAMPTZ,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

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

CREATE TABLE "loans" (
  "id" UUID DEFAULT gen_random_uuid() NOT NULL,
  "copy_id" UUID NOT NULL,
  "member_id" UUID NOT NULL,
  "due_on" DATE NOT NULL,
  "returned_on" DATE,
  "created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
  PRIMARY KEY ("id")
);

ALTER TABLE "book_authors" ADD CONSTRAINT "fk_book_authors_book_id" FOREIGN KEY ("book_id") REFERENCES "books" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "book_authors" ADD CONSTRAINT "fk_book_authors_author_id" FOREIGN KEY ("author_id") REFERENCES "authors" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "copies" ADD CONSTRAINT "fk_copies_book_id" FOREIGN KEY ("book_id") REFERENCES "books" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;

ALTER TABLE "loans" ADD CONSTRAINT "fk_loans_copy_id" FOREIGN KEY ("copy_id") REFERENCES "copies" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "loans" ADD CONSTRAINT "fk_loans_member_id" FOREIGN KEY ("member_id") REFERENCES "library_members" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "holds" ADD CONSTRAINT "fk_holds_book_id" FOREIGN KEY ("book_id") REFERENCES "books" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;

ALTER TABLE "holds" ADD CONSTRAINT "fk_holds_member_id" FOREIGN KEY ("member_id") REFERENCES "library_members" ("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.