Naming of ID columns in database tables

后端 未结 23 735

I was wondering peoples opinions on the naming of ID columns in database tables.

If I have a table called Invoices with a primary key of an identity column I would c

23条回答
  •  时光取名叫无心
    2020-11-29 18:16

    My vote is for InvoiceID for the table ID. I also use the same naming convention when it's used as a foreign key and use intelligent alias names in the queries.

     Select Invoice.InvoiceID, Lines.InvoiceLine, Customer.OrgName
     From Invoices Invoice
     Join InvoiceLines Lines on Lines.InvoiceID = Invoice.InvoiceID
     Join Customers Customer on Customer.CustomerID = Invoice.CustomerID
    

    Sure, it's longer than some other examples. But smile. This is for posterity and someday, some poor junior coder is going to have to alter your masterpiece. In this example there is no ambiguity and as additional tables get added to the query, you'll be grateful for the verbosity.

提交回复
热议问题