Search code examples
sql-serverjdbcdatabase-metadata

List user defined views from database


Is there a way to list user defined views alone. In MSSQL, when I tried to list tables and views using getTables() function of DatabaseMetadata of jdbc, it is showing all the views. But I don't need system views into my result set.

DatabaseMetadata dmd = connection.getMetaData();
tablesResultSet= dmd.getTables(dbName, null, null, new String[] { "TABLE", "VIEW" });

This is the code, I'm using to extract metadata. Can anyone help me to solve this?


Solution

  • You might ask the database directly with a SELECT call and analyse the result:

    SELECT * FROM sys.objects WHERE [type]='V' AND is_ms_shipped=0
    

    [type]='V' will filter for VIEWs and is_ms_shipped=0 will filter for objects which are created by users (were not installed from MS)

    Find details here