Customer Database Structure
The Customer module manages all customer-related data in Magento 2, including customer accounts, addresses, and customer groups. Like the Catalog module, it uses the EAV (Entity-Attribute-Value) pattern for flexible attribute management.
Key Relationships
Note: This is a simplified diagram showing the main relationships.
Core Customer Tables
customer_entity
The main customer entity table. Each row represents a registered customer account.
| Column | Type | Description | 
|---|---|---|
| entity_id | int | Primary key | 
| website_id | smallint | Website ID where customer registered | 
| varchar | Customer email address | |
| group_id | smallint | Customer group ID | 
| store_id | smallint | Store view ID where customer registered | 
| created_at | timestamp | When the customer account was created | 
| updated_at | timestamp | When the customer account was last updated | 
| is_active | smallint | Whether the customer account is active | 
customer_entity_* (EAV Value Tables)
These tables store the actual attribute values for customers. There are separate tables for different data types.
| Table | Data Type | Example Attributes | 
|---|---|---|
| customer_entity_varchar | String values | firstname, lastname, middlename | 
| customer_entity_int | Integer values | gender, is_subscribed | 
| customer_entity_decimal | Decimal values | reward_points, store_credit | 
| customer_entity_text | Long text values | custom notes, preferences | 
| customer_entity_datetime | Date/time values | dob (date of birth) | 
Customer Address Tables
customer_address_entity
Stores customer addresses. Each customer can have multiple addresses.
| Column | Type | Description | 
|---|---|---|
| entity_id | int | Primary key | 
| parent_id | int | Foreign key to customer_entity.entity_id | 
| created_at | timestamp | When the address was created | 
| updated_at | timestamp | When the address was last updated | 
| is_active | smallint | Whether the address is active | 
customer_address_entity_* (EAV Value Tables)
Similar to customer attributes, address attributes are also stored in EAV tables.
- customer_address_entity_varchar- For street, city, firstname, lastname, etc.
- customer_address_entity_int- For is_default_billing, is_default_shipping, etc.
- customer_address_entity_text- For long text values
Customer Group Tables
customer_group
Defines customer groups, which can be used for pricing, discounts, and permissions.
| Column | Type | Description | 
|---|---|---|
| customer_group_id | int | Primary key | 
| customer_group_code | varchar | Group name | 
| tax_class_id | int | Tax class associated with this group | 
Customer Authentication Tables
customer_password_reset_link
Stores password reset tokens for customers.
| Column | Type | Description | 
|---|---|---|
| customer_id | int | Foreign key to customer_entity.entity_id | 
| token | varchar | Reset token | 
| created_at | timestamp | When the token was created | 
customer_log
Logs customer login activity.
| Column | Type | Description | 
|---|---|---|
| customer_id | int | Foreign key to customer_entity.entity_id | 
| last_login_at | timestamp | Last successful login time | 
| last_logout_at | timestamp | Last logout time | 
Customer Segment Tables
customer_segment
Defines customer segments for targeted marketing (Enterprise Edition only).
| Column | Type | Description | 
|---|---|---|
| segment_id | int | Primary key | 
| name | varchar | Segment name | 
| description | text | Segment description | 
| is_active | smallint | Whether the segment is active | 
| created_at | timestamp | When the segment was created | 
| updated_at | timestamp | When the segment was last updated | 
customer_segment_customer
Maps customers to segments (many-to-many relationship).
| Column | Type | Description | 
|---|---|---|
| segment_id | int | Foreign key to customer_segment.segment_id | 
| customer_id | int | Foreign key to customer_entity.entity_id | 
| added_date | timestamp | When the customer was added to the segment | 
| updated_date | timestamp | When the customer's segment membership was updated | 
Data Analysis Tips
- For basic customer information, use EAV joins on value tables.
- For customer address analysis, join customer_address_entitywith its EAV tables.
- For customer activity, use customer_logandsales_ordertables.
- To find attribute IDs, query eav_attributefor the customer entity type.
