ER model
- SQL course
- Expert
- Lesson 1/45
- 5 min
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.idEntity 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
-- customer table
CREATE TABLE customersSample solution
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
CREATE TABLE customers (____)
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 |