只是想知道如何在视图的一个查询中列出列名和表名.
例如:
名为viewC的视图由tbl1内连接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视图中获得:
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>'