只是想知道如何在一个视图查询中列出列名和表名。
例如:
名为viewC,创建者tbl1 inner join tbl2,的视图包含a,b,c,d列(a,bfromtbl1和c,dfrom tbl2)。
viewC
tbl1 inner join tbl2
a,b,c,d
a,b
tbl1
c,d
tbl2
如何
Select COLUMN_NAME, DATA_TYPE, column_default, character_maximum_length, sourceTableNAME FROM information_schema.columns where table_name='viewC'
一起?
这些信息可从以下INFORMATION_SCHEMA视图获得:
INFORMATION_SCHEMA
SELECT * FROM INFORMATION_SCHEMA.VIEW_COLUMN_USAGE AS cu JOIN INFORMATION_SCHEMA.COLUMNS AS c ON c.TABLE_SCHEMA = cu.TABLE_SCHEMA AND c.TABLE_CATALOG = cu.TABLE_CATALOG AND c.TABLE_NAME = cu.TABLE_NAME AND c.COLUMN_NAME = cu.COLUMN_NAME WHERE cu.VIEW_NAME = '<your view name>' AND cu.VIEW_SCHEMA = '<your view schema>'
如果您的视图包含来自多个数据库的表,则查询将变得更加复杂