3 ms·
I have found that naming ids as <thing>_id helps downstream code when trying to figure out which thing's id you are dealing with. It also helps with avoiding r
by psadri 2y ago
I have found that naming ids as <thing>_id helps downstream code when trying to figure out which thing's id you are dealing with. It also helps with avoiding renaming fields when a structure contains multiple ids.
I do agree it makes joins more verbose.
- otteromkram 2y agoThis isn't a great idea. Maybe it works for you, but you can alias it, too. The main identification column of a table should just be id. Any foreign keys can have a table prefix. Please don't prefix the main table id with the table name.
- thiht 2y agoThe fact the "USING" keyword exists would disagree with you. I also use "id" but I would say SQL was designed with the opinion that ids should be prefixed with the table name.
- psadri 2y agoMost of the schemas I have worked with used “id”. I agree it’s the default. But aliasing was inconsistent and made it hard to figure out which table id is being referred to later in the code. I know it is a matter of discipline but any tool that encourages consistency helps. A database schema is definitely one of those tools. One unrelated idea is to include the entity in the id itself. I have never done this but I’d imagine it would help with things like logging / observability. It would not play nice with indices though.