Reputation: 187
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?
Upvotes: 1
Views: 2822
Reputation: 458
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.
Upvotes: 0
Reputation: 67331
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 VIEW
s and is_ms_shipped=0
will filter for objects which are created by users (were not installed from MS)
Upvotes: 3