My first question in here. I like the site so much :)
I've a SQL table called Product. In that table I want to make a column for the ID of the product, and I really want to know the right way to write ID because I make a lot of ID columns in the long run.
So is it: "ID" or "Id" ?
And also a foreign key in another table, is that called ProductID or ProductId?
Capitalization in SQL is largely a matter of coding style. Consistency is the most important aspect. That said, "ProductId" looks a little like "Productld" (that's a lower-case-L before the "d") to me, so I'd prefer "ProductID" (or "productID" or "product_id").
As for prefixing column names with table names, it's too much in my book. Products.id
is sufficient; Products.productID
is redundant.
There isn't a "right" way of doing it. Just be consistent. My personal preference is to use ProductId in both tables. If you use "ID" for all your tables and then join onto another table you will likely end up aliasing them anyway to distinguish between the two ID fields.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With