Imagine a dealer portal that stores all its orders in one wide table: every row carries the order number, dealer name, dealer address, product name, quantity and price. For the first few weeks nothing goes wrong. Then a dealer moves, a product name is corrected, a dealer is deactivated, and the numbers stop agreeing with each other. Data modeling is the schema design that solves these problems before any code is written: it decides what becomes a record of its own, how records connect, and which piece of information lives in exactly one place.
In this guide we cover entities, attributes and relationships, the ER diagram, primary and foreign keys, first, second and third normal form, deliberate denormalization, price history, using a status instead of deleting, the multi-tenant column, a naming standard and a set of review questions. All figures are illustrative; they are not measurements from a real project or industry.
What Is Data Modeling?
Data modeling is the work of describing the concepts in a business area (dealer, order, product) and the relationships between them as tables, columns and rules in a database. It happens at three levels: the conceptual model says "a dealer places orders" in business language; the logical model defines tables, keys and relationships; the physical model chooses data types, indexes and partitioning.
This article focuses on the logical model. Which kind of database to use is a separate question covered in our guide on how to choose a database, and query speed is the subject of our indexing guide. The schema is the ground both of them stand on: neither a powerful database nor an index can rescue a badly shaped schema.
We recommend reading: Our custom software service
What Are Entities, Attributes and Relationships?
An entity is a thing tracked separately in the business area and usually becomes a table. An attribute is a property of the entity and becomes a column. A relationship is a link between two entities, and the number of links on each side (cardinality) drives the design.
| Relationship type | Meaning | Dealer portal example | How it is built |
|---|---|---|---|
| 1-1 | A record has at most one counterpart | Dealer and dealer credit profile | A separate table with the same key, or extra columns in one table |
| 1-N | One record links to many records | One dealer places many orders | A foreign key on the "N" side (order.dealer_id) |
| N-N | Both sides have many counterparts | An order contains many products, a product appears in many orders | A junction table (order_line) |
| Self-referencing | A table points to itself | Category and parent category | parent_category_id in the same table |
An ER (entity-relationship) diagram draws this structure as boxes and lines, so that the business side and the developers look at the same picture before any code exists. Write a glossary first: is a "customer" the same as a "dealer", and when does an "order" differ from a "quote"? These questions should already be answered during requirements analysis.
How Do You Model a Many-to-Many (N-N) Relationship with a Junction Table?
An N-N relationship cannot be stored in a single column; it needs a junction table that joins the two sides. The junction table is not just a link, it also carries information that belongs to the link.
In the order and product example the junction table is order_line: order_id, product_id, quantity and the unit price on that day. Quantity is a property of neither the order nor the product; it belongs to the combination, which is why it lives in the junction table. The primary key can be the pair (order_id, product_id), with a uniqueness rule so the same product cannot be entered twice in one order.
In the illustrative example 10,000 orders hold 6 lines on average: 10,000 × 6 = 60,000 line rows. Products and categories are also N-N: 2,000 products with 2.5 categories each means 2,000 × 2.5 = 5,000 junction rows. If you stored categories as a comma-separated list instead, finding the products in one category would mean splitting text every time, and consistency checks would become impossible.
What Are Primary, Foreign and Surrogate Keys?
A primary key is the value that identifies each row of a table on its own. A foreign key is a column that points to another table's primary key and lets the database enforce the rule "an order cannot be written for a dealer that does not exist".
| Topic | Natural key (such as a tax number) | Surrogate key (sequential number or random identifier) |
|---|---|---|
| Meaning | Comes from the business, carries meaning | Meaningless, serves only as an identity |
| Can it change? | Yes; it may be mistyped or the rule may change | No; it never changes |
| Cost of a correction | Every table that references it is updated | One row is updated |
| Uniqueness rule | The key itself | Needs a separate unique constraint |
In the illustrative example a dealer's tax number was entered wrongly and must be corrected. If the tax number were the primary key, the dealer's 20 orders (on average) and the dealer record would have to change together: 21 rows. With a surrogate key only the dealer row changes: 1 row. The common practice is to make the surrogate key the primary key and put a separate unique constraint on the tax number. That way the identity never changes, and two dealers still cannot be created with the same tax number.
What Is Normalization? 1NF, 2NF and 3NF with Examples
Normalization splits repeated information into separate tables to prevent inconsistency. Each normal form includes the one before it.
| Form | Rule | Example of a violation | Fix |
|---|---|---|---|
| 1NF | One value per cell, no repeating column groups | Columns product1, product2, product3, or text such as "A12, B07" | One row per product (a line table) |
| 2NF | In a table with a composite key, every column depends on the whole key | Key is (order_no, product_code) but product_name depends only on product_code | Move product_name to the product table |
| 3NF | A non-key column does not depend on another non-key column | dealer_name in the order table: order → dealer_id → dealer_name | Move dealer_name to the dealer table |
First, the cost of the single flat table. It holds 10,000 orders with 6 lines each: 60,000 rows. The dealer name (30 bytes on average) and address (90 bytes on average) repeat in every row: 120 bytes × 60,000 = 7,200,000 bytes, about 7.2 MB. In third normal form with 500 dealers, the dealer table takes 500 × 120 = 60,000 bytes and the order table carries only dealer_id (4 bytes): 10,000 × 4 = 40,000 bytes. The total is 100,000 bytes, about 0.1 MB. The difference is 7.1 MB, a 98.6% reduction, or 72 times smaller.
Storage is not the real problem; disk is cheap. The real problem is consistency. The same goes for product names: in a line table keyed by (order_no, product_code), product_name (40 bytes on average) repeats across 60,000 rows: 2,400,000 bytes. After 2NF, 2,000 product rows take only 80,000 bytes. When a product is renamed, the flat table needs 60,000 ÷ 2,000 = 30 rows updated on average, the normalized one needs 1.
What Are Update, Insert and Delete Anomalies?
A table that is not normalized produces three kinds of errors.
- Update anomaly: The average dealer has 10,000 ÷ 500 = 20 orders and 20 × 6 = 120 rows. An address change must touch all 120. If a job is interrupted after 118 rows, the share updated is 118 ÷ 120 = 98.3% and 2 rows keep the old address, so the dealer appears to have two addresses.
- Insert anomaly: A new dealer who has not ordered yet cannot be entered, because dealer data lives only in order rows.
- Delete anomaly: When a dealer's only order is deleted, the dealer's information disappears with it.
In third normal form the dealer has its own table: the address sits in one row, a dealer without orders can be added, and deleting an order leaves the dealer intact. Consistency also has limits under concurrent writes; the problems that appear when two transactions change the same record at once are covered in our concurrency guide.
When Is Deliberate Denormalization Justified?
Denormalization means repeating information on purpose in a normalized model for a measured need. The rule: normalize first, then deviate only where measurement shows a need.
A typical example is the order total. If a list of 50 orders computes each total from its lines, 50 × 6 = 300 line rows are read; if the total is stored on the order table, 50 rows are read. The price is the risk of inconsistency: a line changes but the total is not updated, and the two values drift apart. Three safeguards are needed: write the total and the lines in the same transaction, run a check query on a schedule that finds mismatches, and document which column is derived. In the illustrative example, if the check finds 37 mismatches among 10,000 orders, the rate is 37 ÷ 10,000 = 0.37% and the root cause should be traced.
How Do You Keep History for Changing Data Such as Price?
When the history of changing information matters, you add a new row with a validity range instead of overwriting. For price, a product_price table carries product_id, price, valid_from and valid_to (open-ended allowed). For example, a product costs ₺100 until 31 March and ₺110 from 1 April; there are two rows, and a rule checks that the ranges do not overlap.
The second decision is how the order line carries the price. If the line reads the price live from the price table, the totals of past orders change whenever the price changes. Example: if this product was sold 3,000 units in past orders, a ₺10 increase changes past revenue by 3,000 × ₺10 = ₺30,000. That is why the unit price at order time is copied onto the line row. This is deliberate denormalization: it looks derivable from the price table, but a past that never changes is a business rule. The storage cost is 8 bytes × 60,000 = 480,000 bytes, about 0.48 MB.
Delete or Use a Status Column? How Does Soft Delete Work?
Soft delete means marking a record as "inactive" or "deleted" instead of removing it physically. Because of related tables, physical deletion has knock-on effects.
In the illustrative example 40 dealers are to be deactivated. At 20 orders per dealer on average, that is 40 × 20 = 800 orders, and with 6 lines each 800 × 6 = 4,800 lines. If cascade delete is on, a single operation removes 40 + 800 + 4,800 = 5,640 rows and historical revenue reports change. If deletion is forbidden, the database raises an error. With a status column only the 40 dealer rows are updated and history is preserved.
Know the costs too: every query needs a status filter, and uniqueness rules can clash with inactive records. Deletion of personal data and retention periods should be set with your legal counsel; soft delete alone does not satisfy a deletion obligation.
What Does the Data Model Look Like in a Multi-Tenant Application?
If the application serves several customers (tenants), every table that belongs to a tenant must carry a tenant identifier. In the shared-schema model each main table gets a tenant_id column, and uniqueness rules are defined within a tenant: (tenant_id, tax_no) is unique, so two different tenants can each hold a dealer with the same tax number.
In the example the tables hold 10,000 + 60,000 + 500 + 2,000 = 72,500 rows in total; a 4-byte tenant column adds 72,500 × 4 = 290,000 bytes, about 0.29 MB. What matters is that no query forgets the tenant filter; enforce it in one central layer. The three data separation approaches and their risks are detailed in our multi-tenant architecture guide.
What Should a Table and Column Naming Standard Look Like?
Consistent naming makes a schema readable and searchable. Decide once as a team and write it down.
| Topic | Suggested rule | Example |
|---|---|---|
| Format | Lowercase, underscores, no accented characters | order_line |
| Table name | One style: always singular or always plural | dealer, order, product |
| Primary key | Always the same name | id |
| Foreign key | Target table name + _id | dealer_id |
| Date and time | A suffix that states meaning and type | created_at, valid_from |
| Boolean field | Question-like or status name | is_active, status |
How Do You Change a Schema Later?
To change the schema of a live system without downtime, plan three steps: first add the new column or table so it allows empty values (expand), then move the data and switch the application to the new structure, and finally remove the old structure (contract). Release each step separately and keep it reversible. If the data to move is large, the trial runs and reconciliation steps in our data migration guide apply as they are.
How Do You Review a Data Model?
Build the model in six steps (glossary, entities, relationships, keys, normalization, review) and test it with these questions before coding.
- Does each table describe one concept? Can its name be explained in one sentence?
- Is the same fact stored in two places? If so, is that deliberate and is there a check query?
- Does every N-N relationship have a junction table with the fields that belong to the link?
- Is history needed for changing information? If so, is there a validity range or a copy?
- Is the delete behavior written down for each foreign key (forbid, cascade, status column)?
- If multi-tenant, are the tenant column and per-tenant uniqueness rules defined?
- How many tables do the five most frequent queries join in this model, and is that reasonable?
- Is the naming standard followed?
We recommend reading: What is ERP? Modules, bill of materials, MRP and selection guide
We recommend reading: What is custom software? Layers, types and the logic of cost
Custom Software and Data Models with İnovabil
At İnovabil our focus is bespoke software built from scratch for your company: custom software, ERP, CRM, e-commerce, web, mobile and integration. In the analysis and design steps recorded on our process page we produce user flows and screen sketches; we suggest settling the glossary and relationships of the data model in the same phase. We do not promise figures or timelines; the scope of the model depends on the project.
We have built CRM, purchasing and mobile for Avcılar İnşaat; a purchasing system for İZBAN; logistics and shipment planning with wholesale order management for Karyak; and warehouse management plus a complaint and support management system for Sleepy. Send us a short summary of your processes and your current tables, and we will draft the first list of entities and relationships together.
We recommend reading: Our software development process: step by step from analysis to launch
Frequently Asked Questions
What is data modeling and why does it matter?
It is the work of describing the concepts, relationships and rules of a business area as tables, keys and constraints. A badly shaped schema produces repetition, inconsistency and expensive migrations; thinking it through early is cheaper than fixing it later.
When should you normalize, and is it always necessary?
For transactional tables such as orders, dealers and products the default is third normal form. If there is a reporting need or a measured performance need, you denormalize deliberately and with controls, but you normalize first.
Should the primary key be a natural field or a surrogate key?
For most transactional tables a surrogate key is safer, because it never changes and a correction touches one row. A natural field such as a tax number is protected with a separate unique constraint.
How is a many-to-many relationship modeled?
With a junction table. In the order and product example the order_line table carries two foreign keys and the fields that belong to the link, such as quantity and unit price; a pair uniqueness rule prevents the same product from being entered twice.
Is it right to use a status column instead of deleting records?
Yes, for records whose history you want to keep, such as orders and dealers. Every query needs a status filter and uniqueness rules need care; for true deletion of personal data, set up a separate disposal process with your legal counsel.