Naming of ID columns in database tables

后端 未结 23 775

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:21

    I do hate the plain id name. I strongly prefer to always use the invoice_id or a variant thereof. I always know which table is the authoritative table for the id when I need to, but this confuses me

    SELECT * from Invoice inv, InvoiceLine inv_l where 
    inv_l.InvoiceID = inv.ID 
    SELECT * from Invoice inv, InvoiceLine inv_l where 
    inv_l.ID = inv.InvoiceLineID 
    SELECT * from Invoice inv, InvoiceLine inv_l where 
    inv_l.ID = inv.InvoiceID 
    SELECT * from Invoice inv, InvoiceLine inv_l where 
    inv_l.InvoiceLineID = inv.ID 
    

    What's worst of all is the mix you mention, totally confusing. I've had to work with a database where almost always it was foo_id except in one of the most used ids. That was total hell.

提交回复
热议问题