如何让用户在一个数据库表中选择列 [英] how to let users to select columns in a database table

查看:109
本文介绍了如何让用户在一个数据库表中选择列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在试图建立一个Web应用程序,允许用户选择给定的数据库表相应的栏目。

We are trying to build an web application that allows users to select appropriate columns for given database table.

我不知道是否有对这些任何API - 我GOOGLE了它白白一段时间。否则,如果你能提供一些线索(图案或样品codeS)如何构建这样的组件,这将是巨大的和AP preciated。

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.

推荐答案

您可以基于您对INFORMATION_SCHEMA视图/表格应用程序。这是SQL Server文档,但是你可以很容易地找到它的其他数据库也:

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

样品SQL后:

select * from INFORMATION_SCHEMA.TABLES

select * from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'users'

如果你想使用该解决方案有很多数据库,从数据库引擎的应用程序分开,可以创建有关定义IMetadataProvider接口,并为不同的数据库实现的:

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:

interface IMetadataProvider {
    ...GetTables();
    ...GetTableColumns();
    ...GetTableRelations();
    //Other functions required by your project
}

您也可以创建自己的查询生成器界面:

You can also create your own query builder interface:

interface IQueryBuilder {
    ...From(string tableName);
    ...Top(int numberOfRows); //TOP for SQL SERVER, LIMIT for MySQL
} 

这篇关于如何让用户在一个数据库表中选择列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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