跟踪视图表/列回到系统表

时间:2015-10-21 19:08:46

标签: sql sql-server-2008

我正在尝试获取有关系统视图表/列从系统表中获取信息的信息。有没有办法找出视图表/列来自哪个系统表?我有这个SQL来获取视图表和列信息。当我尝试获取系统表信息时,我会收到大量数据,这些数据很接近,但信息很多。任何帮助,将不胜感激。我环顾四周,有些问题与此有关,但没有找到有帮助的问题。

- 这将获取视图表/列信息

SELECT 
    A.NAME AS 'VIEW_TABLE_NAME'
    , D.NAME AS 'VIEW_COLUMN_NAME'
    , CASE WHEN D.IS_NULLABLE = 0 THEN 'NO' ELSE 'YES' END AS NULLABLE
FROM 
    SYS.VIEWS A
LEFT JOIN 
    SYS.SCHEMAS C ON A.SCHEMA_ID = C.SCHEMA_ID
LEFT JOIN 
    SYS.COLUMNS D ON D.OBJECT_ID = A.OBJECT_ID
WHERE
    A.NAME LIKE 'QL%'
ORDER BY 
    A.NAME, D.NAME, D.IS_NULLABLE

当我在系统表中添加时,我收到了太多信息。

SELECT 
    A.NAME AS 'VIEW_TABLE_NAME', D.NAME AS 'VIEW_COLUMN_NAME'
    , CASE WHEN D.IS_NULLABLE = 0 THEN 'NO' ELSE 'YES' END AS NULLABLE
    , T.NAME AS 'TABLE_NAME'
FROM 
    SYS.TABLES T
LEFT JOIN 
    SYS.VIEWS A ON A.SCHEMA_ID = T.SCHEMA_ID
LEFT JOIN 
    SYS.SCHEMAS C ON A.SCHEMA_ID = C.SCHEMA_ID
LEFT JOIN 
    SYS.COLUMNS D ON D.OBJECT_ID = A.OBJECT_ID --AND D.OBJECT_ID = T.OBJECT_ID
WHERE
    A.NAME LIKE 'QL%'
GROUP BY 
    A.NAME, D.NAME, D.IS_NULLABLE, T.NAME 
ORDER BY 
    A.NAME

感谢您的帮助

0 个答案:

没有答案