locked
How can i get user login name on an Azure sql server ? RRS feed

  • Question

  • User1253338400 posted

    I am trying to get login names via the following:

           use testdb;

           If not exists(Select * from sys.database_principals where name = 'testuser')
                             and not Exists(SELECT * from master.sys.sql_logins where name = 'testuser')

    but it gives error:

        Reference to database and/or server name in 'master.sys.sql_logins' is not supported in this version of SQL Server.

    How can i get these users from the testdb bty referencing the master  ?

    Wednesday, March 10, 2021 4:40 AM

Answers

  • User753101303 posted

    Hi,

    Azure SQL does not allow cross-database queries this way (ie you can't use a server or database name as part of a table identifier).
    If reallly needed you likely have to use https://docs.microsoft.com/en-us/azure/azure-sql/database/elastic-query-getting-started-vertical that uses the CREATE EXTERNAL TABLE I noticed once.

    Here it doesn't seems something that should be routinely used but rather for database maintenance? On Azure SQL the idea is likely to avoid depending on the master database.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 10, 2021 5:21 PM