MySQL使用另一个表中的列名 [英] MySQL use column names from another table

查看:203
本文介绍了MySQL使用另一个表中的列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以返回一个结果集,其中列名存储在一个单独的表中。这是可能的,还是需要一个带有变量的stored_procedure。请参阅mysql_dump的链接和所需的结果集的描述:

I'm wondering if it is possible to return a result set with column names which are stored in a separate table. Is this possible or do I need a stored_procedure with variables. See link for mysql_dump and description of required resultset:

http: /pastie.org/584865

推荐答案

您必须使用可以动态生成SQL的存储过程然后运行它。列名不是SQL中真正的一流数据,所以你不能做任何事情。它们在查询解析时确定,然后执行查询或获取任何数据。

You'd have to use a stored procedure that'd generate SQL dynamically and then run it. Column names aren't really first-class data in SQL, so you can't do much anything with them. They are determined at query parse time, before executing the query or fetching any data.

我建议在您的应用程序中执行此操作。只要您的应用程序显示/保存/无论正确的名称,而不是数据库列名称。

I suggest doing it in your app instead. Just have your app display/save/whatever the correct names instead of the database column names.

PS:您可能会滥用关系模型。请非常仔细地考虑,如果你真的想要那个架构。 工作表告诉你哪种类型?

PS: You are abusing the relational model horribly. Please very carefully consider if you really want that schema. Your schema fails the first normal form. And what is worksheet_type_lookup for? Doesn't worksheets tell you which type?

这篇关于MySQL使用另一个表中的列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆