Schema Definition

Entity Relationship Diagram

Last updated

What is an ERD?

An Entity Relationship Diagram (ERD) is a visual representation of database tables and their relationships. ERDs show entities (tables), attributes (columns), and relationships (foreign keys) in a clear, structured format. They're essential for database design, documentation, and communication between developers and stakeholders.

ERDs help you plan database structure before implementation, identify potential issues, and document existing databases. They show primary keys, foreign keys, data types, and cardinality (one-to-one, one-to-many, many-to-many relationships).

ERD Components

Schema Example:
User
- id: INT PRIMARY KEY
- name: VARCHAR(100)
- email: VARCHAR(100)

Post
- id: INT PRIMARY KEY
- user_id: INT FOREIGN KEY -> User.id
- title: VARCHAR(200)

Common Use Cases

1. Database Design

Plan database structure before implementation. Visualize tables, relationships, and constraints. Identify normalization opportunities and potential issues early in the design process.

2. Documentation

Document existing database schemas for team members and stakeholders. ERDs provide clear visual documentation that's easier to understand than SQL DDL statements.

3. Database Migration

Plan database migrations and schema changes. Visualize how new tables and relationships fit into existing structure. Identify affected tables and relationships.

4. Team Communication

Communicate database design to non-technical stakeholders. ERDs are more accessible than raw SQL and help everyone understand data structure.

5. Learning and Teaching

Teach database concepts and normalization. ERDs make abstract database concepts concrete and visual, helping students understand relationships and design principles.

ERD Examples

Example 1: Blog System

User
- id: INT PRIMARY KEY
- username: VARCHAR(50)
- email: VARCHAR(100)

Post
- id: INT PRIMARY KEY
- user_id: INT FOREIGN KEY -> User.id
- title: VARCHAR(200)
- content: TEXT

Comment
- id: INT PRIMARY KEY
- post_id: INT FOREIGN KEY -> Post.id
- user_id: INT FOREIGN KEY -> User.id
- content: TEXT

Example 2: E-commerce

Customer
- id: INT PRIMARY KEY
- name: VARCHAR(100)
- email: VARCHAR(100)

Order
- id: INT PRIMARY KEY
- customer_id: INT FOREIGN KEY -> Customer.id
- total: DECIMAL(10,2)
- status: VARCHAR(20)

OrderItem
- id: INT PRIMARY KEY
- order_id: INT FOREIGN KEY -> Order.id
- product_id: INT FOREIGN KEY -> Product.id
- quantity: INT
- price: DECIMAL(10,2)

Product
- id: INT PRIMARY KEY
- name: VARCHAR(200)
- price: DECIMAL(10,2)
- stock: INT

Example 3: Social Network

User
- id: INT PRIMARY KEY
- username: VARCHAR(50)
- bio: TEXT

Friendship
- id: INT PRIMARY KEY
- user_id: INT FOREIGN KEY -> User.id
- friend_id: INT FOREIGN KEY -> User.id
- status: VARCHAR(20)

Post
- id: INT PRIMARY KEY
- user_id: INT FOREIGN KEY -> User.id
- content: TEXT
- created_at: TIMESTAMP

Like
- id: INT PRIMARY KEY
- user_id: INT FOREIGN KEY -> User.id
- post_id: INT FOREIGN KEY -> Post.id

Example 4: School Management

Student
- id: INT PRIMARY KEY
- name: VARCHAR(100)
- email: VARCHAR(100)

Course
- id: INT PRIMARY KEY
- name: VARCHAR(100)
- credits: INT

Enrollment
- id: INT PRIMARY KEY
- student_id: INT FOREIGN KEY -> Student.id
- course_id: INT FOREIGN KEY -> Course.id
- grade: VARCHAR(2)

Teacher
- id: INT PRIMARY KEY
- name: VARCHAR(100)
- department: VARCHAR(50)

Example 5: Library System

Book
- id: INT PRIMARY KEY
- title: VARCHAR(200)
- isbn: VARCHAR(13)
- author: VARCHAR(100)

Member
- id: INT PRIMARY KEY
- name: VARCHAR(100)
- membership_number: VARCHAR(20)

Loan
- id: INT PRIMARY KEY
- book_id: INT FOREIGN KEY -> Book.id
- member_id: INT FOREIGN KEY -> Member.id
- loan_date: DATE
- return_date: DATE

Frequently Asked Questions

What format should I use for schema input?
Use the simple text format shown in the example. Start with entity name, then list fields with "- field_name: DATA_TYPE". Add PRIMARY KEY or FOREIGN KEY -> Entity.field for constraints.

Frequently Asked Questions

Yes, our Erd Generator is completely free with no registration required. Use it unlimited times without any restrictions.

Yes, all processing happens locally in your browser. Your data never leaves your device and is not stored on our servers.

No installation needed. The tool works directly in your web browser on any device.

Simply click the generate button and the tool will create a secure, random output instantly. You can customize options if available.

Yes, use the available options to adjust the output format and parameters to match your needs.