如何让用户选择数据库表中的列
我们正在尝试构建一个 Web 应用程序,允许用户为给定的数据库表选择适当的列。
我想知道是否有针对这些的 API - 我在谷歌上搜索了一段时间,但没有成功。否则,如果您可以提供一些如何构建此类组件的线索(模式或示例代码),那就太好了并且值得赞赏。
We are trying to build an web application that allows users to select appropriate columns for given database table.
I wonder if there is any API for these - I've googled it a while in vain. Otherwise, if you can give some clues (patterns or sample codes) how to build such a component, that will be great and appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将您的应用程序基于 INFORMATION_SCHEMA 视图/表。这是 SQL Server 的文档,但您也可以轻松找到其他数据库的文档:
http ://msdn.microsoft.com/en-us/library/ms186778.aspx
示例 SQL:
如果您想将此解决方案与多个数据库一起使用,要将应用程序与数据库引擎分开,您可以创建有关定义IMetadataProvider 接口并为不同的数据库创建实现:
您还可以创建自己的查询生成器接口:
You could base your application on INFORMATION_SCHEMA views/table. This is documentation for SQL Server, but you can easily find it for other databases too:
http://msdn.microsoft.com/en-us/library/ms186778.aspx
Sample SQLs:
if you want to use this solution with many databases, to separate your application from db engine, you can create about defining IMetadataProvider interface and create implementations for different databases:
You can also create your own query builder interface: