我们应该在数据库表命名约定中使用前缀吗?

发布于 2024-07-09 16:00:03 字数 217 浏览 7 评论 0原文

我们正在工作中的开发团队决定表、列、过程等的命名约定。 单复数表命名已经决定,我们使用单数。 我们正在讨论是否为每个表名使用前缀。 我想阅读有关是否使用前缀以及原因的建议。

它是否提供任何安全性(至少为可能的入侵者多了一个障碍)? 我认为用前缀命名它们通常更舒服,以防我们在代码中使用表的名称,这样就不会将它们与变量、属性等混淆。但我想阅读更有经验的开发人员的意见。

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, we are using singular. We are discussing whether to use a prefix for each table name or not. I would like to read suggestions about using a prefix or not, and why.

Does it provide any security at all (at least one more obstacle for a possible intruder)? I think it's generally more comfortable to name them with a prefix, in case we are using a table's name in the code, so to not confuse them with variables, attributes, etc. But I would like to read opinions from more experienced developers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

少钕鈤記 2024-07-16 16:00:03

我发现匈牙利数据库对象前缀来指示其类型相当烦人。

我曾在每个表名都必须以“tbl”开头的地方工作过。 在每种情况下,当有人需要进行较小的更改时,命名约定最终都会造成很大的痛苦。

例如,如果您的约定是表以“tbl”开头,视图以“v”开头,那么当您决定用后端的其他一些东西替换表并提供兼容性或视图时,正确的做法是什么?即使作为首选界面? 我们最终得到了以“tbl”开头的视图。

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".

李白 2024-07-16 16:00:03

我更喜欢使用应用程序或解决方案的短名称作为表和其他数据库对象的前缀。

这有助于解决两种可能出现的情况:

  1. 如果您选择使用任何需要应用程序数据库中的表的第三方框架组件(例如 asp net 会员提供程序),则不太可能出现命名冲突。

  2. 如果您正在为客户开发解决方案,他们可能仅限于单个数据库(特别是如果他们支付外部托管费用),要求他们将多个应用程序的数据库对象存储在单个数据库中。

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.

小姐丶请自重 2024-07-16 16:00:03

我不明白任何命名约定如何提高安全性......

如果入侵者有权访问数据库(具有有害权限),他们肯定有权列出表名并选择查看它们的用途。

但我认为真正令人困惑的表名可能会间接恶化安全性。
这将使进一步的开发变得困难,从而减少安全问题得到解决的机会,甚至可能隐藏潜在的问题:

如果一个名为(例如)“sro235onsg43oij5”的表充满了带有随机字符串和数字的随机命名列,则一个新的开发人员可能只是认为它是随机测试数据(除非他接触了与之交互的代码),但如果它被命名为“userpasswords”或类似名称,任何查看该表的开发人员可能都会对密码以明文形式存储感到震惊。

I don't see how any naming convention can improve security...

If an intruder have access to the database (with harmful permissions), they will certainly have permissions to list table names and select to see what they're used for.

But I think that truly confusing table names might indirectly worsen security.
It would make further development hard, thus reducing the chance security issues will be fixed, or it could even hide potential issues:

If a table named (for instance) 'sro235onsg43oij5' is full of randomly named coloumns with random strings and numbers, a new developer might just think it's random test data (unless he touches the code that interact with it), but if it was named 'userpasswords' or similar any developer who looks at the table would perhaps be shocked that the passwords is stored in plaintext.

耳根太软 2024-07-16 16:00:03

为什么不根据您现有的编码指南来命名表呢? 将表名视为“类”,将列视为“属性”或“字段”。 当使用可以从类/成员命名自动推断表/列命名的 ORM 时,这会有所帮助。

例如,Castle ActiveRecord,声明如下假设名称与他们所在的成员相同

[ActiveRecord]
public class Person
{
    [PrimaryKey]
    public Int32 Id { get; set; }

    [Property]
    public String Name { get; set; }
}

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; }
}
阪姬 2024-07-16 16:00:03

如果您使用 SqlServer,好的开始是查看提供的示例数据库以获得一些指导。

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

苏佲洛 2024-07-16 16:00:03

过去,我一直反对在表名和列名中使用前缀。 然而,当面临重新设计系统的任务时,拥有前缀对于执行搜索和替换非常有价值。 例如,grep 查找“tbl_product”可能会比 grep 查找“product”提供更相关的结果。

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".

三岁铭 2024-07-16 16:00:03

如果您担心混淆表名称,请在代码中使用匈牙利表示法样式系统。 也许“s”代表字符串+“tn”代表表名:

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

当然,前缀由您决定,具体取决于您喜欢代码的详细程度... strtblUsers,strtblnmeUsers,thisisthenameofatableyouguysUsers...

在表名中添加前缀确实有一些好处,特别是如果您不将该前缀硬编码到系统中,并允许它在每次安装时进行更改。 首先,正如 Ian 所说,您与其他组件发生冲突的风险较小,其次,如果您愿意,您可以让程序的两个或多个实例在同一个数据库上运行。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文