r/SQL • u/donewitheverything26 • Sep 01 '26
Discussion where do you actually write down what a column means
Inherited a schema where roughly half the columns are self-explanatory and the rest are things like flag_3 and val_b. Person who built it left. There's a Confluence page describing six columns, last edited before most of them existed.
I've been using COMMENT ON COLUMN because it lives with the database and can't drift into a stale wiki. Downside is nobody looks at it, it doesn't show up anywhere people work, and I've no way to know if a comment is still true after a migration.
Things I'm unsure about:
does anyone actually keep COMMENT ON up to date at scale, or does it rot the same as the wiki just less visibly
if a column's meaning changes but the name doesn't, is there anything that catches that, or is it purely a review discipline problem
and for the columns nobody can explain at all, do you leave them, drop them, or keep them with a comment saying unknown
I've been profiling the values to guess — cardinality, null rate, distributions — which narrows it but never gets me to what the thing means.
31
u/mac-0 Sep 01 '26
How are these tables built? Typically if you're using DBT or something you'd document it in the table's config.
24
u/JeLuF Sep 01 '26
Usually in git where all the sql files live that I used to create/alter the tables.
11
u/Zestyclose-Turn-3576 Sep 01 '26
When I worked with a COTS marketing system it had database tables named as "T0000001", "T00000002" etc, and columns "T0000001C001" blah blah.
We put views over the top of each one to provide meaningful names for the reporting system, and accessed those instead.
8
u/BrupieD Sep 01 '26
We usually have Excel source to target mappings and use extended properties (SQL Server). Source-to-target documents get cumbersome, but they tend to be really complete. Extended properties show up in table properties and when you script out the create table statements -- they're highly accessible although brief.
6
u/iama_bill Sep 01 '26
I’m a fan of the data dictionary since it’s easier to query. In my case, the database gets deployed in many environments and the schema will vary depending on the code release of an upstream transactional system. Even though there’s a lot of overlap with information_schema.tables and columns, it adds things like the subject area and category of table, how it links to the source, descriptions, etc.
You ultimately need someone to be willing to update it unless changes are made as part of a broader pipeline that reminds people to describe whatever they’re adding.
5
u/RecordGlobal4338 Sep 01 '26
You need a data catalog , I used cloudera one, very useful.
3
u/satans_weed_guy Sep 01 '26
The definition/description of a column belongs in that column's metadata. Documentation can be built from that, and AI can be skilled to read from that. As far as developing psychic powers to figure out what previous developers intended, I can't help you there. But I do know your pain.
3
u/creed_1 Sep 01 '26
I’ve never used comments on columns. I’ve always made sure the columns name had meaning to it and it would be in the sql or plsql code that shows what the column does there.
3
u/ihaxr Sep 02 '26
Create a view and name the columns in the view with more care
I heavily use extended properties, but wouldn't expect it to contain column level information unless a column requires special care
2
u/cleverchris Sep 01 '26
I understand your pain. And the reality is there probably isn't a solution you (or me) would be satisfied with. I have found that if you can define the unit of the field it goes a very long way toward providing the context. If a unit is not concievable I try to use a binary (t or f; y or n) if I need more I try and fit it to a 0-1 scale. If all your fields have 1 of these 3 things you should be able to work out their meanings. Of course I am not at all talking about char fields.
2
u/feignapathy Sep 01 '26
source to target mapping
STTM
we just use Excel files right now
2
u/kagato87 MS SQL Sep 01 '26
The calling application should have all of this documented in the code.
We have a description field in the xml that orm uses to generate scripts, and enums that explain the contents. (Enums that get exported to an enum table in the database even, so I can support codes that product hasn't even thought of yet.)
2
u/just_an_avg_dev Sep 01 '26
"No one knows what it means, but it's provocative" - 2011 Jay-Z track.
66
u/BrentOzar Sep 01 '26
You guys know what the columns mean?!?
1
u/chaosink Sep 01 '26
I do not envy you your task and wish you good luck. I have gone through this several times and it suckssucksit makes you feel better, the worst one was figuring out a database that was built in Korean, hacked by Turks, and then plopped in my lap to figure out the columns which were a combination of both. Our front end was a MMORPG so we had people in game doing things to leave markers we could find in the columns.Canary in a coalmine stuff. Do you have any control or access to what is putting data into the db?
That was back when Netscape was just getting overtaken by Explorer so it sucked. If I had to do it today, I would use my local LLM to assist since I could feed it the backend, the front end code, and ask it to do a massive reference check with confidence scores. It would have been so much easier with a model trained in the languages.
2
u/db_tech_dev Sep 01 '26
honestly COMMENT ON rots too, just slower and quieter than the wiki because nobody's forced to look at it during a review. what actually caught drift for us was adding a dbt model with column descriptions in the yaml - it's still just docs, but since it sits in the PR diff next to the SQL change, people actually update it when they touch the column. for the totally unknown ones we just prefix them unknown_ or add a comment saying "meaning lost, inherited schema, do not trust" instead of guessing, saves the next person from repeating your profiling work.
2
u/feather_media Sep 02 '26
hello tech debt my old friend...
2
u/lolcrunchy Sep 01 '26
You smell like ai
1
u/millerlit Sep 02 '26
Data dictionary
1
u/ArielCoding Sep 02 '26
For the columns nobody can explain, try looking at when they change, if you have an updated_at, audit log, or CDC history, find a few timestamps where the mystery column’s values flipped, then check what else changed at the same moment.
1
u/seagulledge Sep 02 '26
Rename the column, then see what breaks. :)
1
u/Blomminator Sep 02 '26
It's really annoying if a name is off. Recently I had to connect with an API, and the username/token was stored in the db. So.. I keep trying and trying... And after half a day or frustration.. I ask my coworker.. "hey, you use this right? Why can't I connect?"
And the answer was... "Yeah the token is not a token, but a pw. Couldn't get token connection working so I switch to another option, and never renamed the column".
Well.. that's great! Thanks!
1
u/Top_Community7261 Sep 02 '26
I use Confluence; it's simple and the features work well for documenting a database. ,
1
u/zaskar Sep 02 '26
Did you ever hear of Darth Hungarian notation, the wise?
1
u/KatFromSisense Sep 02 '26
For the columns that nobody can explain, I'd keep the guess separate from the definition. Something like: status = unknown, suspected meaning = customer tier, evidence = values 0-4 / changes with X, owner = whoever can confirm it.
The profiling still gives you something useful to work with. But I wouldn't let "probably customer tier" slowly become "customer tier" just because nobody revisited it for a while. If nobody can confirm the column, I'd keep it and leave the uncertainty visible.
1
u/Scrapper_John Sep 02 '26
Extended properties
1
u/pppeto Sep 02 '26
We use entity framework for data access + generated classes from db schema. The tool, that generates the classes reads the metadata and adds comments on the class and it's properties. For code archeology, Claude or Codex are working quite well.
1
u/RandomiseUsr0 Sep 04 '26
Make it someone’s job to manage a data dictionary, people leave, things go stale, autos things are useful now - I’ve had to train my agents to mistrust things that humans have left (well, not accept it by default) because especially metadata, does go stale in your schema comments especially - without special care)
1
u/Jaded_Spray_6855 Sep 08 '26
i was a solo data analyst at a post-seed startup and i inherited all the tables with zero documentation. what i did was get Claude to store everything in notion as i encountered them, which was slow but got better over time once i started using the same tables over and over again
1
u/Aggressive-Video-508 Sep 09 '26
On your second question — nothing catches it automatically, but you can make it visible, and the trick is in how the description is written rather than where it's stored.
A free-text comment ("customer tier") drifts silently because nothing in it has to agree with anything else. What has worked for me is writing the definition as two checkable parts: the words the name is made of (
cust= customer,tier= ranking bucket — a short shared word list, one meaning per word), and for any coded column, the set of valid values with their meanings (0 none, 1 bronze, 2 silver, 3 gold). Now when someone repurposestierto mean something else, either the name stops matching the word list or a value shows up that isn't in the set. Neither needs a human to remember to re-read the comment — a profiling job like the one you're already running can diff the observed values against the declared set, and a naming check can flag a name whose words aren't on the list. That's the closest thing to "something catches it" I've found; the rest is review discipline, as you suspected.That also patches the hole in the unit advice for your three 0–4 integers: same unit, but the value set with meanings is different per column, and "unknown — observed values 0–4, no nulls, suspected rating" is itself a legitimate entry until someone confirms it. Keep the suspected marker on it, as another comment said.
For where it lives: put the word list and the value sets in the repo next to the migrations, and generate the
COMMENT ONstatements from that file rather than hand-writing them. Then the comments in the catalog can't be older than the file, and the file is in the diff whenever someone touches the column.