Search code examples
azure-sql-databaseazure-sql-server

Check whether EXTERNAL DATA SOURCE exist in Azure SQL


I am new to Azure SQL Database. I have a EXTERNAL DATA SOURCE as listed in following link.

CREATE EXTERNAL DATA SOURCE

CREATE EXTERNAL DATA SOURCE [My_data_src] WITH (TYPE = RDBMS, LOCATION = N'myserver', CREDENTIAL = [my_cred], DATABASE_NAME = N'MyDB')

GO

Before creating a new EXTERNAL DATA SOURCE, I need to find out whether this already exists. is there any query or dmv existing to find this?


Solution

  • The following command give you list of all existing External Data Source in database

    select  *  from sys.external_data_sources;
    

    To check particular External Data Source, exist or not use following command:

    IF  EXISTS (
    SELECT  name
    FROM sys.external_data_sources
    WHERE [name] =  'Name of Datasource'
    )
    BEGIN
    PRINT  'Yes'
    END
    

    It will print Yes if Data Source Exist.

    Refer - sys.external_data_sources (Transact-SQL)