What is a table prefix?

后端 未结 7 1523
一整个雨季
一整个雨季 2020-12-30 23:01

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

7条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-30 23:37

    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.

提交回复
热议问题