Sql naming best practice

前端 未结 12 2734
春和景丽
春和景丽 2021-02-14 09:48

I\'m not entirely sure if there\'s a standard in the industry or otherwise, so I\'m asking here.

I\'m naming a Users table, and I\'m not entire

12条回答
  •  感动是毒
    2021-02-14 10:19

    As other answers suggest, it is a personal preference - pick up certain naming schema and stick to it.
    Some 10 years ago I worked with Oracle Designer and it uses naming schema that I like and use since then:

    • table names are plural - USERS
    • surrogate primary key is named as singular of table name plus '_id' - primary key for table USERS would be "USER_ID". This way you have consistent naming when you use "USER_ID" field as foreign key in some other table
    • column names don't have table name as prefix.

    Optionally:

    • in databases with large number of tables (interpret "large" as you see fit), use 2-3 characters table prefixes so that you can logically divide tables in areas. For example: all tables that contain sales data (invoices, invoice items, articles) have prefix "INV_", all tables that contain human resources data have prefix "HR_". That way it is easier to find and sort tables that contain related data (this could also be done by placing tables in different schemes and setting appropriate access rights, but it gets complicated when you need to create more than one database on one server)

    Again, pick naming schema you like and be consistent.

提交回复
热议问题