<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: True Rows</title>
    <description>The latest articles on DEV Community by True Rows (@truerows).</description>
    <link>https://dev.to/truerows</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4263701%2Ff6d3a027-f0c0-45a7-82d0-50b216c3b92e.png</url>
      <title>DEV Community: True Rows</title>
      <link>https://dev.to/truerows</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/truerows"/>
    <language>en</language>
    <item>
      <title>Don't Hard-Code Your Statuses: A Practical Common-Codes Table Design</title>
      <dc:creator>True Rows</dc:creator>
      <pubDate>Wed, 25 Nov 2026 13:00:00 +0000</pubDate>
      <link>https://dev.to/truerows/dont-hard-code-your-statuses-a-practical-common-codes-table-design-24dg</link>
      <guid>https://dev.to/truerows/dont-hard-code-your-statuses-a-practical-common-codes-table-design-24dg</guid>
      <description>&lt;p&gt;Order status, payment method, gender, document type: almost every business screen has a field where the user picks one value from a fixed list. It is tempting to put those values in an enum, a &lt;code&gt;CHECK&lt;/code&gt; constraint, or a &lt;code&gt;switch&lt;/code&gt; in the application. That works until someone asks for a new status, or the same list starts to drift across screens.&lt;/p&gt;

&lt;p&gt;A common-codes table moves those values into data. An administrator can add, rename, or deactivate a code on a screen, and dropdowns, radio buttons, and search filters all read from the same place. The design looks simple. What usually goes wrong later is how the rest of the system refers to it.&lt;/p&gt;

&lt;p&gt;Below is the two-table starting point I use, along with its trade-off and a short checklist for a design review.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two tables: the group and the item
&lt;/h2&gt;

&lt;p&gt;A code never lives alone. &lt;code&gt;PAID&lt;/code&gt; belongs to order status; &lt;code&gt;CARD&lt;/code&gt; belongs to payment method. Put the information that applies to the whole set — the group name, a description, and an active flag — in &lt;code&gt;code_group&lt;/code&gt;. Put the values themselves in &lt;code&gt;code_item&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;code_group                      code_item
+-----------------------+       +----------------------------+
| PK   group_code       | 1   N | PK,FK  group_code          |
|      group_name       |------&amp;lt;| PK     item_code           |
|      group_description|       |        code_name           |
|      is_active        |       |        sort_order          |
+-----------------------+       |        parent_item_code FK |
                                |        attribute_1 .. 5    |
                                |        is_active           |
                                +----------------------------+
                                       |              ^
                                       |              | self-reference,
                                       +--------------+ same group only
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The relationship is identifying: because &lt;code&gt;group_code&lt;/code&gt; is part of the item's primary key, an item cannot exist without its group. A shortened form, written with generic SQL types and usable on PostgreSQL, is below. I have left out the audit columns (&lt;code&gt;created_at&lt;/code&gt;, &lt;code&gt;created_by&lt;/code&gt;, &lt;code&gt;updated_at&lt;/code&gt;, &lt;code&gt;updated_by&lt;/code&gt;) that I would add to every table. Lengths are examples.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;code_group&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;group_code&lt;/span&gt;         &lt;span class="kt"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;group_name&lt;/span&gt;         &lt;span class="kt"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;group_description&lt;/span&gt;  &lt;span class="kt"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;is_active&lt;/span&gt;          &lt;span class="kt"&gt;BOOLEAN&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="kc"&gt;TRUE&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;CONSTRAINT&lt;/span&gt; &lt;span class="n"&gt;pk_code_group&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;group_code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;code_item&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;group_code&lt;/span&gt;         &lt;span class="kt"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;item_code&lt;/span&gt;          &lt;span class="kt"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;code_name&lt;/span&gt;          &lt;span class="kt"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;code_description&lt;/span&gt;   &lt;span class="kt"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;sort_order&lt;/span&gt;         &lt;span class="kt"&gt;INTEGER&lt;/span&gt;       &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;parent_item_code&lt;/span&gt;   &lt;span class="kt"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;attribute_1&lt;/span&gt;        &lt;span class="kt"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="c1"&gt;-- and attribute_2 .. attribute_5&lt;/span&gt;
    &lt;span class="n"&gt;is_active&lt;/span&gt;          &lt;span class="kt"&gt;BOOLEAN&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="kc"&gt;TRUE&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;CONSTRAINT&lt;/span&gt; &lt;span class="n"&gt;pk_code_item&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;group_code&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;item_code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;CONSTRAINT&lt;/span&gt; &lt;span class="n"&gt;fk_code_item_group&lt;/span&gt;
        &lt;span class="k"&gt;FOREIGN&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;group_code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;REFERENCES&lt;/span&gt; &lt;span class="n"&gt;code_group&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;group_code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;CONSTRAINT&lt;/span&gt; &lt;span class="n"&gt;fk_code_item_parent&lt;/span&gt;
        &lt;span class="k"&gt;FOREIGN&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;group_code&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;parent_item_code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;REFERENCES&lt;/span&gt; &lt;span class="n"&gt;code_item&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;group_code&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;item_code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second foreign key is what makes the hierarchy safe. &lt;code&gt;parent_item_code&lt;/code&gt; lets items in the same group form a tree — for example, a document type with subtypes. Because the key is (&lt;code&gt;group_code&lt;/code&gt;, &lt;code&gt;parent_item_code&lt;/code&gt;) pointing at (&lt;code&gt;group_code&lt;/code&gt;, &lt;code&gt;item_code&lt;/code&gt;), the database rejects a parent from another group.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the primary key is a composite
&lt;/h2&gt;

&lt;p&gt;The primary key is (&lt;code&gt;group_code&lt;/code&gt;, &lt;code&gt;item_code&lt;/code&gt;), not the item code alone, so the same item code can be reused in different groups. A numeric style such as &lt;code&gt;10&lt;/code&gt;, &lt;code&gt;20&lt;/code&gt;, &lt;code&gt;30&lt;/code&gt; can appear in more than one group. In examples I prefer to ship, I use mnemonic values such as &lt;code&gt;PAID&lt;/code&gt; and &lt;code&gt;CARD&lt;/code&gt;, which are easier to read in SQL. Either style is fine if you use it consistently.&lt;/p&gt;

&lt;p&gt;The spare columns &lt;code&gt;attribute_1&lt;/code&gt; through &lt;code&gt;attribute_5&lt;/code&gt; cover operational extras without a program change: a payment-gateway mapping code, or a flag that controls whether the value appears on a particular screen. The column name itself tells you nothing, so record what each spare column means, per group, in &lt;code&gt;group_description&lt;/code&gt; or in the table specification. A year later, nobody will remember otherwise.&lt;/p&gt;

&lt;h2&gt;
  
  
  The convention you must not lose
&lt;/h2&gt;

&lt;p&gt;Here is the part that is easy to miss. A business table almost never stores both parts of that key. The &lt;code&gt;order_status_code&lt;/code&gt; column on a sales order stores only the item code — &lt;code&gt;PAID&lt;/code&gt;, &lt;code&gt;SHIPPED&lt;/code&gt;, and so on. The developer already knows which group the column uses. The values live in the database; which group they come from is a convention in the specification and in the program.&lt;/p&gt;

&lt;p&gt;That usual practice has a clear cost. You cannot declare a proper foreign key from &lt;code&gt;sales_order.order_status_code&lt;/code&gt; to &lt;code&gt;code_item&lt;/code&gt;, and every join has to name the group:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sales_order_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;order_status_code&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;code_name&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;order_status_name&lt;/span&gt;
  &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales_order&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;
  &lt;span class="k"&gt;LEFT&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;code_item&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;
    &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;item_code&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;order_status_code&lt;/span&gt;
   &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;group_code&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'ORDER_STATUS'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;ORDER_STATUS&lt;/code&gt; is, in effect, hard-coded — or, better, a shared constant. If you forget the group condition, a join can pick up a row from the wrong group.&lt;/p&gt;

&lt;p&gt;To drop the group condition from the join, you either make item codes unique across the whole system, or you store a reference key — a surrogate such as &lt;code&gt;code_item_id&lt;/code&gt;, or the group and the item together. The first reduces reuse. The second makes the business tables a little heavier, and a surrogate alone no longer tells you what the code means when you look at a row.&lt;/p&gt;

&lt;p&gt;I still store the item code, because it is readable in queries and in logs. The group convention then has to live somewhere reliable. The most dependable place I have found is the table specification: in the remarks for &lt;code&gt;order_status_code&lt;/code&gt;, write the group and the expected values — for example, "Common code (ORDER_STATUS: PAID, PROCESSING, SHIPPED, …)". Keep that same group in one shared constant, and use it for dropdowns, validation, and joins.&lt;/p&gt;

&lt;h2&gt;
  
  
  When a single table, or no table, is better
&lt;/h2&gt;

&lt;p&gt;You can fold the two tables into one, with top-level rows acting as groups and child rows as items. The code value itself is then the primary key, so values must be unique across the system. If order status already uses &lt;code&gt;10&lt;/code&gt;, payment method cannot; you prefix them, &lt;code&gt;ORD_10&lt;/code&gt; and &lt;code&gt;PAY_10&lt;/code&gt;. The gain is that a business table can store one code and declare a real foreign key.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Comparison&lt;/th&gt;
&lt;th&gt;Two tables (&lt;code&gt;code_group&lt;/code&gt; + &lt;code&gt;code_item&lt;/code&gt;)&lt;/th&gt;
&lt;th&gt;Single table&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Reusing item codes&lt;/td&gt;
&lt;td&gt;Yes (&lt;code&gt;10&lt;/code&gt; can appear in several groups)&lt;/td&gt;
&lt;td&gt;No (values must be unique system-wide)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Foreign key from a business table&lt;/td&gt;
&lt;td&gt;Not possible if only the item code is stored&lt;/td&gt;
&lt;td&gt;Possible with a single code&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Group-level information&lt;/td&gt;
&lt;td&gt;Lives on &lt;code&gt;code_group&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Lives on the top-level row&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;A better fit when&lt;/td&gt;
&lt;td&gt;Many groups, and the group/item split is already familiar&lt;/td&gt;
&lt;td&gt;A new system that wants database-level referential integrity first&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A shared table that holds many kinds of codes is often called a One True Lookup Table (OTLT), and it is widely treated as an anti-pattern. The criticism is fair: you give up a proper foreign key when you store only the item code, every code shares the same type and length, and spare attributes hide their meaning. I accept those costs for a specific reason. In business systems, administrators add and deactivate codes on a screen, and many screens build a dropdown with one generic query. Creating a new table and shipping a release for every new set of codes usually costs more. The safeguards below are what make that trade-off safe.&lt;/p&gt;

&lt;p&gt;Use a dedicated lookup table when a set of codes has its own attributes or rules, or when business tables must have a real foreign key — for example, a &lt;code&gt;job_grade&lt;/code&gt; table, not a row in &lt;code&gt;code_group&lt;/code&gt;. For a small, almost unchanging set that nobody will manage on an admin screen, a &lt;code&gt;CHECK&lt;/code&gt; constraint or an enum is enough.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pitfalls that show up in production
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Do not change a code value that is already in use.&lt;/strong&gt; Business tables store that value. If you change &lt;code&gt;PAID&lt;/code&gt; to &lt;code&gt;SETTLED&lt;/code&gt; in &lt;code&gt;code_item&lt;/code&gt;, existing orders are left with a code that no longer has a name. You may change the display name; leave the code itself alone.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Do not physically delete a code.&lt;/strong&gt; Set &lt;code&gt;is_active&lt;/code&gt; to &lt;code&gt;FALSE&lt;/code&gt;. Dropdowns should list only active codes; lookups for existing rows should still resolve the name. If you can, revoke &lt;code&gt;DELETE&lt;/code&gt; on the code tables from the application's database account.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Do not rely on a foreign key from the business table to reject bad codes.&lt;/strong&gt; When the table stores only the item code, that foreign key is usually not there. The save service — the service-layer logic that writes the row — should check that the group and item exist and that the item is active. The same check should cover APIs, file uploads, and batch jobs, not only the screen.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Make &lt;code&gt;is_active&lt;/code&gt; and &lt;code&gt;sort_order&lt;/code&gt; &lt;code&gt;NOT NULL&lt;/code&gt;&lt;/strong&gt;, with &lt;code&gt;is_active&lt;/code&gt; defaulting to &lt;code&gt;TRUE&lt;/code&gt;. A null flag is a common reason a code disappears from a dropdown and nobody can see why.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  A short design checklist
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Group and item are split when you need to reuse item codes; a single table is used when you do not.&lt;/li&gt;
&lt;li&gt;[ ] A dedicated lookup table is used when a code set has its own attributes or rules, or needs a real foreign key.&lt;/li&gt;
&lt;li&gt;[ ] Every code column in a business table has its group recorded in the table specification (and in one shared constant in the program).&lt;/li&gt;
&lt;li&gt;[ ] The meaning of each spare attribute is recorded per group.&lt;/li&gt;
&lt;li&gt;[ ] A parent item is allowed only within the same group (enforced by the composite foreign key).&lt;/li&gt;
&lt;li&gt;[ ] Item codes in use are not changed; only display names are.&lt;/li&gt;
&lt;li&gt;[ ] Codes are deactivated with &lt;code&gt;is_active = FALSE&lt;/code&gt;, never physically deleted.&lt;/li&gt;
&lt;li&gt;[ ] The save service checks that the group and item exist and that the item is active.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The structure is not complicated. What keeps it safe is the convention you write down, and the checks you run when a row is saved.&lt;/p&gt;

&lt;p&gt;I wrote more on this pattern, and on the table designs that usually come after it — role-based permissions, effective-dated prices, HR, purchasing, and e-commerce — in &lt;em&gt;Before You CREATE TABLE: Database Design Patterns for Business Systems, from Codes and Permissions to HR, Purchasing, and E-commerce&lt;/em&gt;. The English edition is on &lt;a href="https://truerows.gumroad.com/l/db-design-patterns" rel="noopener noreferrer"&gt;Gumroad&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;True Rows writes from 20+ years of work on enterprise system integration (SI) projects in Korea, focused on business analysis and database design.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>database</category>
      <category>sql</category>
      <category>postgres</category>
      <category>datamodeling</category>
    </item>
  </channel>
</rss>
