简体   繁体   English

MySQL-具有多个架构的数据库,其中表和列的名称不同

[英]MySQL - Database with multiple schemas where table and column names are different

Is there a way to have one database that can be represented with different table and column names? 有没有一种方法可以使用不同的表名和列名来表示一个数据库?

I'm creating a large refactoring of an API, where it only makes sense to rename quite some table and column names in the MySQL database, but the old version of the API still needs to read and write to the existing database. 我正在创建一个大型的API重构,仅在MySQL数据库中重命名一些表名和列名才有意义,但是旧版本的API仍需要读写现有数据库。 The data is largely the same and the versions can easily co-exist. 数据基本相同,并且版本可以轻松共存。 There is no chance to have two databases running in parallel. 没有机会让两个数据库并行运行。

The new API domain layer is fully separated from the persistance layer, but in the persistance layer, I would like to create it properly using new table and column names, instead of having to convert the names for each query. 新的API域层与持久性层完全分开,但是在持久性层中,我想使用新的表名和列名正确地创建它,而不必为每个查询转换名称。

Is there a way to represent the database structure in multiple ways - effectively making the naming variable? 有没有一种方法可以用多种方式表示数据库结构-有效地命名变量? Can you suggest me a solution? 你能建议我一个解决方案吗? Is there eg a way to solve this by replacing a database schema? 是否有例如通过替换数据库架构来解决此问题的方法?

I would like the two versions of the API to read and write to database where tables can exist with this (below) difference in naming - but the table and data is the same. 我希望API的两个版本可以读写数据库,在这些数据库中表可以存在(以下)命名方式上的差异-但表和数据是相同的。

+----------------------------+  +-------------------------+
|          old_items         |  |        new_items        |
+----+----------+------------+  +----+----------+---------+
| id | meta_key | meta_value |  | id | item_key | item_id |
+----+----------+------------+  +----+----------+---------+

The application is written in PHP. 该应用程序是用PHP编写的。

Thanks. 谢谢。

Why you want to rename the column, when you can use alias when getting the column name. 为什么要重命名列,以及在获取列名称时可以使用别名的原因。 like 喜欢

select metavalue as itemvalue from tablename

Or 要么

Alternatively you can create two seperate tables for each your entity. 另外,您可以为每个实体创建两个单独的表。 That makes sense. 那讲得通。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM