1

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?

abubakkar
  • 187
  • 13

2 Answers2

3

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

Arockia Nirmal
  • 737
  • 1
  • 6
  • 20
Shnugo
  • 66,100
  • 9
  • 53
  • 114
0

You have to take the schema into consideration. The default schema on MS SQL is dbo. So your call to the metadata should be:

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

Or you get all Schemas before by

dmd.getSchemas(dbName,"%");

And then loop all your 'working' schemas.

Fredy Fischer
  • 458
  • 3
  • 12