如何在sql中获取表名和列名 [英] How to get table name and column name in sql
问题描述
我想创建一个查询构建器,我想在asp.net中使用sql server显示我的表及其列,如何代码实体部分
EasyQuery - 网站的即席查询构建器。演示页面。
但是我能够帮助我如何做到这一点。
谢谢
穆罕默德
我尝试了什么:
我使用了列表框和复选框列表,并为获取表名和列创建了一个视图。
I want to make a query builder and I want to show my table and their column like this in asp.net with sql server and how to code entity part
EasyQuery - ad-hoc query builder for web-sites. Demo page.
but I am anble to do this kindly help me how to do this .
thanks
mohammad
What I have tried:
I used list box and checkbox list and make a view for fetch table name and column.
推荐答案
试试这个:
Try this:
SELECT t.name AS table_name,
SCHEMA_NAME(schema_id) AS schema_name,
c.name AS column_name
FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
ORDER BY schema_name, table_name;
以上查询的来源可以在这里找到:
SQL SERVER–查询从所有数据库表中查找列–与Pinal Dave一起探索SQL权威 [ ^ ]
祝你好运!
Source for the above query can be found here:
SQL SERVER – Query to Find Column From All Tables of Database – Journey to SQL Authority with Pinal Dave[^]
Good luck!
你可以这样做
you could do this
SELECT name
FROM sys.tables
WHERE OBJECT_ID IN ( SELECT id
FROM syscolumns
WHERE name like '%COlName%' )
这篇关于如何在sql中获取表名和列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!