Legacy schema traps
Twenty reasons your SQL does not match the screen.
Legacy business systems keep the meaning of their data in the application, not in the schema. These are the traps we meet again and again: what they look like, why reports and AI agents get them wrong, and a first check you can run yourself.
Run the free schema checkFree · five minutes · only schema and aggregates leave you
Keys and relations
- Why do my SQL joins return rows from the wrong company?Many legacy systems put a company or site code in front of every key, so customer 1000 in company 01 and customer 1000 in company 02 are different customers.
- My ERP database has no foreign keys. How do I know what joins to what?Most legacy databases declare few or no foreign keys; the relations live in the application code and in naming habits.
- Why does one table hold all the codes in my ERP?One “code table” holds dozens of lists (payment terms, regions, order types) told apart only by a type column.
- Why do old orders show the wrong customer?Some systems reuse numbers after a record is deleted or after a yearly reset, so the same number means different things in different years.
Status, flags and deletion
- Why does my SQL total not match the ERP screen?The system marks rows as deleted, cancelled or replaced with a flag instead of removing them, and the screens hide them.
- What do the status numbers in my ERP database mean?Status is a number where ranges matter (10–19 open, 20–29 delivered, 90+ closed), and the meaning exists only in the application.
- The order is closed, but its lines are still open. Which one is right?Header and line each carry their own status, and they disagree in ways the application resolves by a rule.
- Why does my ERP use J, Y, 1 and blank for the same flag?Boolean fields hold several spellings of yes and no, plus blank, often from different program versions.
Dates and time
- Why are dates stored as numbers in my old ERP?Dates are stored as integers or strings in formats such as YYYYMMDD, CYYMMDD or day numbers since a base date.
- Why do I see orders due on 31 December 9999?Special values such as 0, 99999999 or 1900-01-01 mean “no date” or “open-ended”.
- Why is the price from SQL different from the price on the order?Prices, discounts and agreements are valid from a date, so the right price depends on customer, item and the date of the order.
- Why do my monthly figures not match the accounts?Accounting periods do not match calendar months (13 periods, a fiscal year starting in May, a closing period).
Money and quantities
- Why are the amounts in my ERP database 100 times too large?Amounts and quantities are stored as integers with an implied number of decimals, sometimes different per column.
- Why do my totals mix euros and kronor?The currency of an amount is stored in another column or another table, sometimes only on the header.
- Why does stock show 12 when we have 144?Quantities are stored in different units (piece, box, pallet) with conversion factors in another table.
- Why are credit notes positive in my ERP database?Whether an amount is a debit or credit, a sale or a return, is carried by a type code rather than by the sign.
Structure and logic outside the tables
- Why does the same field mean different things for different customers?A field is reused for another purpose by one company, one record type or after a certain year.
- Why are there twelve columns for one value in my database?Months, warehouses or price levels are stored as repeated columns (QTY01…QTY12) instead of rows.
- The numbers on screen are calculated. Where is the calculation?Rules live in triggers, stored procedures or a nightly batch, so the stored value is not the value users see.
- Why are there customers called TEST in our production database?Test companies, test customers and migrated history sit next to real data, and screens or reports quietly exclude them.
Run the free schema checkFind the traps in your own database. Free schema check, five minutes.