2 ms·
My other favorite best practice with SQL is to have unique ID column names, so you never mix up IDs, and can use JOIN with the USING syntax: SELECT * FROM
by arnaudsm 1y ago
My other favorite best practice with SQL is to have unique ID column names, so you never mix up IDs, and can use JOIN with the USING syntax:
SELECT *
FROM customer
JOIN order USING (customer_id)
- jiggawatts 1y agoMy reason for doing this is that there can be multiple foreign key columns pointing at the same table, each with a distinct purpose and name. The general case is a named key.
- vbezhenar 1y agoI've never heard of `using` syntax. And now you might make me reconsider my identifier naming usage :) It certainly makes sense.
- 5123121 1y agoThe downside of this is GORM ( or new developer ) often just default to "id". Fighting against it will take away bits of your attention and effort.
- arnaudsm 1y agoYep, it's unfortunately the industry standard, but in my career I've seen it lead to mixing up ids and painful debugging.