Create Your First Entity in an ERD
Learn how to create your first entity (table) in an Entity-Relationship Diagram. Covers entity naming, defining columns with data types, and setting primary keys.
Detailed Explanation
What is an Entity?
In ER modeling, an entity represents a real-world object or concept that you want to store data about. In relational database terms, an entity maps directly to a table. Each entity has a name and a set of attributes (columns) that describe its properties.
Anatomy of an Entity
A well-defined entity includes:
| Component | Purpose | Example |
|---|---|---|
| Entity name | Identifies the table | users |
| Primary key | Uniquely identifies each row | id SERIAL |
| Attributes | Data stored about the entity | name VARCHAR(255) |
| Data types | Define what kind of data each column holds | INT, TEXT, BOOLEAN |
| Constraints | Rules like NOT NULL, UNIQUE | email VARCHAR(320) NOT NULL UNIQUE |
Step-by-Step: Creating Your First Entity
Choose a clear name: Use a plural noun in
snake_case(e.g.,users,products,order_items). The name should describe what collection of things the table stores.Define the primary key: Almost every entity needs a primary key column. The most common patterns are:
id SERIAL— auto-incrementing integer (PostgreSQL)id INT AUTO_INCREMENT— auto-incrementing integer (MySQL)id UUID— universally unique identifier
Add attributes: Think about what data you need to store. Each attribute becomes a column with a data type. Start with the essential columns and add more later.
Set constraints: Mark columns as
NOT NULLif they are required,UNIQUEif values must not repeat, and setDEFAULTvalues where appropriate.
Example: A Simple Users Entity
CREATE TABLE users (
id SERIAL PRIMARY KEY,
username VARCHAR(255) NOT NULL UNIQUE,
email VARCHAR(320) NOT NULL UNIQUE,
is_active BOOLEAN NOT NULL DEFAULT true,
created_at TIMESTAMP NOT NULL DEFAULT NOW()
);
In the ERD editor, this entity appears as a card with the table name in the header and each column listed below, color-coded by key type: gold for the primary key (id) and the default color for regular columns.
Use Case
You are starting a new project and need to design the database from scratch. Creating your first entity — typically the central entity like users, products, or events — is the foundation upon which all other tables and relationships will be built.