我在MySQL的test
数据库中有一些表名。我在数据库mapping
中有一个名为renamed
的表,其中包含已重命名的表的信息。
现在我想要一个test
数据库中的表列表及其在mapping
表中重命名的名称。
test
123_abc
124_abc
235_test
mapping
表格中的信息
table renamed
123_abc 123_abc_test
235_test 235_testing
abc_test abc_test1
现在我想要一个列表,其中包含test
数据库中的表名以及mapping
数据库中renamed
表中的重命名名称
预期结果是
123_abc 123_abc_test
235_test 235_testing
我怎样才能做到这一点?
答案 0 :(得分:1)
您可以发出类似的
之类的MySQL语句 select * from renamed.mapping inner join information_schema.tables on renamed.mapping.table_name = information_schema.tables.TABLE_NAME where information_schema.tables.TABLE_SCHEMA='test'
答案 1 :(得分:0)
您可以使用属于MySQL的information_schema数据库,其中包含所有MySQL的元信息(包括表名),如下所示:
select t1.TABLE_NAME, t2.table_name
from information_schema.`TABLES` t1
where table_schema = 'test'
inner join renamed.mapping t2 on
t1.table_name = t2.table_name
当然,使用内部联接,您只能获得实际重命名的表。如果您想要测试模式中的所有表,请改为执行左连接。