更新时间:2022-11-25 08:41:37
对于 2005 年及以后的版本,这些都将满足您的需求.
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
对于 2000,这将给出 instance 中的 数据库 列表.
For 2000, this will give a list of the databases in the instance.
SELECT * FROM INFORMATION_SCHEMA.SCHEMATA
这就是@Adrift 的回答中提到的向后不兼容".
That's the "backward incompatability" noted in @Adrift's answer.
在 SQL Server 2000(及更低版本)中,实际上并没有这样的模式",尽管您可以以类似的方式将角色用作命名空间.在这种情况下,这可能是最接近的等价物.
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