I want to retrieve a list of all schemas in a given Sql Server database. Using the ADO.NET
schema retrieval API, I get a list of all collections but there is no collection for 'Schemas'.
I could traverse the 'Tables'
, 'Procedures'
collections (and others if required) and obtain a list of unique schema names but isn't there a easier/shorter way of achieving the same result?
Example: For the standard 'AdventureWorks'
database I would like to obtain the following list - dbo,HumanResources,Person,Production,Purchasing,Sales
(I've omitted the other standard schem names like db_accessadmin
,db_datareader
etc)
Edit: I can get the list of schemas by querying the system view - INFORMATION_SCHEMA.SCHEMATA
but would prefer using the schema API as first choice.