Naming of ID columns in database tables

后端 未结 23 744

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

    If you give each key a unique name, e.g. "invoices.invoice_id" instead of "invoices.id", then you can use the "natural join" and "using" operators with no worries. E.g.

    SELECT * FROM invoices NATURAL JOIN invoice_lines
    SELECT * FROM invoices JOIN invoice_lines USING (invoice_id)
    

    instead of

    SELECT * from invoices JOIN invoice_lines
        ON invoices.id = invoice_lines.invoice_id
    

    SQL is verbose enough without making it more verbose.

提交回复
热议问题