Naming of ID columns in database tables

后端 未结 23 770

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

    FWIW, our new standard (which changes, uh, I mean "evolves", with every new project) is:

    • Lower case database field names
    • Uppercase table names
    • Use underscores to separate words in the field name - convert these to Pascal case in code.
    • pk_ prefix means primary key
    • _id suffix means an integer, auto-increment ID
    • fk_ prefix means foreign key (no suffix necessary)
    • _VW suffix for views
    • is_ prefix for booleans

    So, a table named NAMES might have the fields pk_name_id, first_name, last_name, is_alive, and fk_company and a view called LIVING_CUSTOMERS_VW, defined like:

    SELECT first_name, last_name
    FROM CONTACT.NAMES
    WHERE (is_alive = 'True')
    

    As others have said, though, just about any scheme will work as long as it is consistent and doesn't unnecessarily obfuscate your meanings.

提交回复
热议问题