什么是表前缀?

发布于 2024-10-08 21:54:56 字数 36 浏览 5 评论 0原文

什么是表前缀,它们的优点和缺点是什么?这与MySQL有关。

What is a table prefix, and what are their advantages and disadvantages? This is in relation to MySQL.

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

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

发布评论

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

评论(7

你列表最软的妹 2024-10-15 21:54:56

这通常用于区分同一脚本的不同安装。
例如,假设您的服务器上有两个内容不同的 Joomla 安装,但只有一个 MySQL 数据库。

现在,由于显而易见的原因,两个 Joomla 安装无法共享相同的数据库表,因为这将导致两个安装显示相同的内容。这就是前缀发挥作用的地方。

通过使用不同的表前缀,您可以让 Joomla Installation #1 知道它应该使用所有带有前缀 JOS_ 的表,而 Joomla Installation #2 必须使用所有带有前缀 JOS2_ 的表

This is often used to distinguish different installations of the same script from each other.
For example let´s say you have two Joomla Installations with different content on your server, but only one MySQL Database.

Now, for obvious reasons both Joomla installations can´t share the same database tables, as that would result in both installations displaying the same contents. And that is where the prefix kicks in.

By using different table prefixes you can let Joomla Installation #1 know that it is supposed to use all the table with Prefix JOS_ and Joomla Installation #2 has to use all the tables with the prefix JOS2_

卖梦商人 2024-10-15 21:54:56

表不需要前缀。

这完全取决于你。

但是,我们为表添加与其所属应用程序中的模块相关的前缀,只是为了更轻松地对表进行分组。

Tables do not require prefixes.

This is purely up to you.

However, we prefix tables with relation to the MODULES in the application they belong to, just to group the tables more easily.

影子是时光的心 2024-10-15 21:54:56

有些人提倡使用 tbl 或 tbl_(例如 tbl_MyTable 或 tblMyTable),而另一些人则使用诸如 MyTable_T 之类的后缀。

我个人避免使用前缀/后缀。如果模式随着时间的推移而变化,我可能会用视图代替表,所以我并没有真正区分这两种类型的对象。

最重要的是,您的团队中记录了命名指南,并且大家都遵循同一套指南以保持一致性。

Some people advocate tbl or tbl_ (e.g. tbl_MyTable or tblMyTable) whilst others go with a suffix such as MyTable_T.

Personally I avoid the prefixes/suffixes. I may substitute in a View in place of a Table if a schema is changing over time so I don't really distinguish between the two types of object.

The most important thing is that you have your naming guidelines documented within your team and you all stick to the same set of guidelines for consistency.

懵少女 2024-10-15 21:54:56

奇怪的是,没有人提到您还可以使用表前缀来使用通常保留的关键字作为表名。

例如,现在可以使用 t_user 或 t_order。

Strange no one mentioned that you also can use table prefixes to use normally reserved keywords as tablenames.

E.g. t_user or t_order are now possible.

第几種人 2024-10-15 21:54:56

如果您有复杂的网站和数据库结构,表前缀可能有助于防止数据库中的命名冲突。

您经常会在以下情况下看到表前缀:

  • 多个脚本被集成到一个网站中,并且完成的网站需要共享数据,但如果每个脚本没有唯一的前缀,表名称可能会发生冲突。

  • 您正在向您获取的脚本添加功能,并且您希望区分该脚本的本机表和您手动创建的新表。这样,如果您创建一个新表,它就不会与基本脚本的任何未来更新冲突,因为它具有不同的表前缀。

  • 您的托管计划仅提供一个数据库,而您希望使用该数据库为多个脚本提供服务。 (出于多种原因不建议这样做,但我见过用户这样做。)

当您从头开始编写脚本时,表前缀通常不是必需的,因为您控制数据库结构的所有方面。当您开始将多个脚本集成在一起时,它就会变得有用,有时甚至是必要的。它允许您在多个脚本之间创建独特的数据视图和连接表等,而无需担心数据库中的命名冲突。

If you have a complicated website and database structure, table prefixes may help prevent naming conflicts in the database.

You often see table prefixes in situations where:

  • Multiple scripts are being integrated together into one website, and the finished website needs to share data, but the table names would conflict without a prefix unique to each script.

  • You are adding functionality to a script you acquired, and you want to distinguish between tables native to that script and new tables you are manually creating. That way if you create a new table, it won't conflict with any future updates to the base script, since it has a different table prefix.

  • You have a hosting plan that only gives you one database and you want to use that database to service multiple scripts. (This isn't recommended for a variety of reasons, but I've seen users do this.)

When you are writing a script from scratch, table prefixes usually aren't necessary since you control all aspects of the database structure. It's when you start integrating multiple scripts together that it becomes useful and sometimes even necessary. It allows you to create unique data views, and join tables, and such between multiple scripts without worrying about naming conflicts in the database.

维持三分热 2024-10-15 21:54:56

在少数情况下,例如创建恶意软件脚本以针对特定类型的网站(例如 WordPress 等)的情况,更改表前缀作为额外的安全措施非常有用。

例如,添加表前缀会掩盖常见的表名称,使黑客更难通过 SQL 注入或其他安全漏洞访问数据库中的数据,因为他们首先需要发现您的表名称是什么。

但是,请务必将表前缀视为非常小的安全层。它不应该是您的主要安全方法。您仍然应该采取其他更重要的安全措施来防止 SQL 注入和其他类似的威胁。例如,根据代码的设置方式,黑客仍然有可能通过 SQL 注入运行“显示表”命令来获取数据库表的名称。

In a small amount of cases, such as those where malware scripts have been created to target specific types of sites such as WordPress etc., changing the table prefixes has been useful as an extra security measure.

For example, adding table prefixes obscures common table names making it harder for hackers to access data in your database through SQL injection or other security holes because they will first need to discover what your table names are.

Be sure, however, to look at table prefixes as only a very minor layer of security. It should NOT be your main security method. You should still be taking other more important security measures to prevent SQL injection and other similar threats. For example, depending on how your code is set up it may still be possible for a hacker to run a "show tables" command through SQL injection to get the names of your database tables.

梦过后 2024-10-15 21:54:56

根据您的命名约定,它可能有助于区分表和视图。

缺点是您可能会受到表名称的限制。 Oracle 对此有 30 个字符的限制。如果使用“Tbl_”作为前缀,则会自动丢失 4 个字符。这可能是个问题。

It may help to distinguish between tables and views depending on what your naming convention is.

The disadvantage is that you may be limited as far as the name of a table is concerned. Oracle has a limit of 30 characters for this. If you use "Tbl_" as the prefix, you automatically lose 4 characters. That may be a problem.

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