例子,sql数据库中查询登陆名和用户(架构)的对应关系。
--MSSQL 2005
SELECT SP.name as [login_name],DP.default_schema_name as [Schema_with_user],DP.name as [user_name]
FROM sys.database_principals DP ,sys.server_principals SP
WHERE SP.sid = DP.sid
--and SP.name='xxx'
--MSSQL 2000
SELECT SP.name as login_name,DP.name as default_schema_name FROM sysusers DP ,master..sysxlogins SP WHERE SP.sid = DP.sid
-- and SP.name = 'sa'