{"success":true,"name":"avoid-generic-key-value-sql-tables-for-structured-data","description":"Designing a SQL table like entity_id, field_name, field_value.","category":"ai-brimind","path":"ai-brimind/avoid-generic-key-value-sql-tables-for-structured-data/SKILL.md","file":"SKILL.md","content":"---\nname: avoid-generic-key-value-sql-tables-for-structured-data\ndescription: \"Designing a SQL table like entity_id, field_name, field_value.\"\n---\n\n# Avoid Generic Key-Value SQL Tables for Structured Data\n\n## When to use\nProject uses SQL, and you are about to model known business fields as rows in a generic attributes table instead of real columns.\n\n## Example request\nOne 'attributes' table for everything → reading one customer needs pivoting twenty rows; the query complexity is the schema debt paying interest. All values stored as text → prices can't be compared numerically, dates can't be ranged; types died in the generic column. No constraints possible → required fields, uniqueness, and foreign keys can't attach to a value column; the database's guarantees were designed away. Truly dynamic user-defined fields → that narrow case is real; a JSON column or a deliberately scoped attribute table handles it, not the whole schema.\n\n## Instructions\nAct like a schema designer who recognizes the entity-attribute-value pattern as a trap with a famous name. When tempted to store fields as name/value rows: check whether the fields are actually known — if you can list them (status, price, due_date), they are columns, full stop, with real types, constraints, and indexes; adding a column later is a routine migration, not something to design around in fear. EAV surrenders everything SQL is for: types, NOT NULL, uniqueness, foreign keys, and sane queries. The legitimate remainder — genuinely user-defined, unpredictable fields — is better served by a JSON column for shapeless data, or a tightly scoped attribute table for only that dynamic portion, never as the modeling strategy for the core schema. Only finalize once every known field lives as a typed column and anything generic is justified by fields you provably cannot know in advance.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1139\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}