How do I obtain a list of all schemas in a Sql Server database

前端 未结 6 1244
温柔的废话
温柔的废话 2020-12-13 11:54

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

6条回答
  •  萌比男神i
    2020-12-13 12:55

    For 2005 and later, these will both give what you're looking for.

    SELECT name FROM sys.schemas
    SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA
    

    For 2000, this will give a list of the databases in the instance.

    SELECT * FROM INFORMATION_SCHEMA.SCHEMATA
    

    That's the "backward incompatability" noted in @Adrift's answer.

    In SQL Server 2000 (and lower), there aren't really "schemas" as such, although you can use roles as namespaces in a similar way. In that case, this may be the closest equivalent.

    SELECT * FROM sysusers WHERE gid <> 0
    

提交回复
热议问题