CodeBlanks Logo Icon CodeBlanks

ER model

Learn the Entity-Relationship model.

ER model

The ER model maps real-world entities and their relationships. Each entity becomes a table, each attribute a column.

-- Varlık: customers
-- İlişki: orders.customer_id -> customers.id

Entity and relationship form the skeleton of data.

ER model — details

The designer first spots entities, then adds attributes, last draws relationships. The diagram lets you see the design before writing tables.

Practice ER model

Create the customers table with id, name, email columns. id is the primary key.

Starter code

query.sql
-- customer table
CREATE TABLE customers

Sample solution

query.sql
CREATE TABLE customers (
  id SERIAL PRIMARY KEY,
  name TEXT NOT NULL,
  email TEXT
);

Expected output

CREATE TABLE

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What does an 'entity' represent in the ER model?

  • A trigger
  • A query
  • A real-world object Correct answer
  • An index

Explanation: An entity represents a real-world object.

2 Create a table for the entity

Question
CREATE TABLE customers (____)
Answer
CREATE TABLE customers (id SERIAL PRIMARY KEY)

Explanation: id SERIAL PRIMARY KEY is the right answer.

3 ER model: match the terms

Term Meaning
entity object
attribute column
relationship link
table table

All lessons in Expert