Should we use prefixes in our database table naming conventions?

前端 未结 7 2181
攒了一身酷
攒了一身酷 2021-02-05 22:03

We are deciding the naming convention for tables, columns, procedures, etc. at our development team at work. The singular-plural table naming has already been decided,

相关标签:
7条回答
  • 2021-02-05 22:43

    I prefer prefixing tables and other database objects with a short name of the application or solution.

    This helps in two potential situations which spring to mind:

    1. You are less likely to get naming conflicts if you opt to use any third-party framework components which require tables in your application database (e.g. asp net membership provider).

    2. If you are developing solutions for customers, they may be limited to a single database (especially if they are paying for external hosting), requiring them to store the database objects for multiple applications in a single database.

    0 讨论(0)
  • 2021-02-05 22:46

    If you're worried about mixing up your table names, employ a hungarian notation style system in your code. Perhaps "s" for string + "tn" for table name:

     stnUsers = 'users';
     stnPosts = 'posts';
    

    Of course, the prefix is up to you, depending on how verbose you like your code... strtblUsers, strtblnmeUsers, thisisthenameofatableyouguysUsers...

    Appending a prefix to table names does have some benefits, especially if you don't hardcode that prefix into the system, and allow it to change per installation. For one, you run less risk of conflicts with other components, as Ian said, and secondly, should you wish, you could have two or instances of your program running off the same database.

    0 讨论(0)
  • 2021-02-05 22:56

    If you use SqlServer the good start would be to look at the sample databases provided for some guidance.

    0 讨论(0)
  • 2021-02-05 23:00

    Why not name the tables according to the guidelines you have in place for coding? Consider the table name a "class" and the columns a "property" or "field". This assists when using an ORM that can automatically infer table/column naming from class/member naming.

    For instance, Castle ActiveRecord, declared like below assumes the names are the same as the member they are on.

    [ActiveRecord]
    public class Person
    {
        [PrimaryKey]
        public Int32 Id { get; set; }
    
        [Property]
        public String Name { get; set; }
    }
    
    0 讨论(0)
  • 2021-02-05 23:01

    In the past, I've been opposed to using prefixes in table names and column names. However, when faced with the task of redesigning a system, having prefixes is invaluable for doing search and replace. For example, grepping for "tbl_product" will probably give you much more relevant results than grepping for "product".

    0 讨论(0)
  • 2021-02-05 23:03

    I find hungarian DB object prefixes to indicate their types rather annoying.

    I've worked in places where every table name had to start with "tbl". In every case, the naming convention ended up eventually causing much pain when someone needed to make an otherwise minor change.

    For example, if your convention is that tables start with "tbl" and views start with "v", thn what's the right thing to do when you decide to replace a table with some other things on the backend and provide a view for compatibility or even as the preferred interface? We ended up having views that started with "tbl".

    0 讨论(0)
提交回复
热议问题