SUSER_SID 支持 Azure SQL

SUSER_SID support for Azure SQL

SUSER_SID 有两个可选参数。我只使用第一个 'login'。它的文档适用于 Azure SQL 数据库,但它不起作用。对于 'login' 参数表示 "Applies to: SQL Server 2008 and later".

当我打电话给SELECT SUSER_SID('test'); 使用 SSMS,我收到错误:

'SUSER_SID' cannot be invoked with parameters in this version of SQL Server.

我正在使用 Azure SQL 服务器版本。 12.0.2000.8

这怎么可能,我错过了什么?

奇怪,这实际上不是 documented,但我遇到了同样的问题。 (将在文档的 GitHub 中提出这个问题)。

如果您想要 sid,您可以使用 sys.database_principals

SELECT dp.sid
FROM sys.database_principals dp
WHERE dp.name = N'test';

对于这个问题,我询问了 Azure 支持。他们告诉我:

Based on the online document, the parameter “login” applies to SQL Server 2008 and later version, and the parameter2 applies to SQL Server 2012 and later version. That is the reason why we will get the error message “'SUSER_SID' cannot be invoked with parameters in this version of SQL Server.” while running the command SELECT SUSER_SID('serveradmin') , because Azure SQL database does not support SUSER_SID() with parameters.

如果您想查看 SID,请考虑 运行 下面的命令:

select name, sid from sys.sql_logins where name = 'test'

截图如下:

希望对您有所帮助。