Use external table on Azure SQL Managed Instance to read data from Azure SQL Database

Published Jul 31 2021 09:45 AM 3,611 Views
Microsoft

Looking for an online way to consume data from Azure SQL Database on Managed Instance?

 

One of the ways to consume data online from Azure SQL Database on Managed Instance is to link the two by creating an external table, using CREATE EXTERNAL DATA SOURCE (Transact-SQL). The external table is created on Managed Instance, which with appropriate credentials can be used to query data from a matching table on SQL Database.

 

DB to MI external table.png

 

This type of setup could be useful to applications that need to consume both Managed Instance and SQL Database data, or perhaps for an online migration of data from SQL Database to Managed Instance. This article explains how to set this up.

 

Networking requirements

 

As the first step, there has to exist connectivity between Azure SQL Database and Managed Instance. The easiest option is to configure public endpoint on SQL Database and an allow inbound traffic on port 1433 from Managed Instance. This will allow Managed Instance to log in and query data from SQL Database. Alternatively, if you would like to use the private endpoint for SQL Database, the easiest option would be to deploy its private endpoint in the same VNet as Managed Instance. In this case as well, please do not forget to allow inbound traffic to SQL Database on port 1433 from Managed Instance subnet. Please note that detailed instructions on setting up the networking is beyond the scope of this article.

 

You'd need to have either of these options setup as the networking requirement:

 

  • Option 1 - public endpoint connection
    • Ensure that public endpoint access is working on SQL Database using a database client (such is SSMS)
    • If needed, open NSG rule on SQL Database side to allow 1433 the inbound traffic

 

  • Option 2 - private endpoint connection
    • Create an additional subnet in Managed Instance VNet
    • Deploy SQL Database private endpoint to the new subnet created inside Managed Instance VNet (see this tutorial for details)

In case that you perhaps have a VM inside the same VNet as Managed Instance, you can use it to test the connectivity to SQL Database. For example, use SSMS from a VM inside the Managed Instance VNet to connect to SQL Database. If this works, then Managed Instance will be able to successfully connect to SQL Database to read data.

 

Prepare table to use Azure SQL Database

 

As the first step, decide which table on SQL Database would you like to expose to Managed Instance. This could be an existing table, or you could perhaps create a new table.

 

The sample code below creates a new table AzureDBtable on an existing SQL Database, and inserts the current time stamp. Hopefully, we'd be able to read off this time stamp from Managed Instance.

 

-- Execute on Azure SQL Database
-- Create table and insert some sample data
CREATE TABLE AzureDBtable (TimeTable datetime2)
INSERT INTO AzureDBtable values (getutcdate())
SELECT @@servername AS [Server name], * FROM AzureDBtable

 

 

Using SSMS, the below shows the table created on SQL Database.

DanimirLjepava_2-1627748654560.png

For the purpose of this article, we have inserted the following time stamp to the table on SQL Database.

DanimirLjepava_0-1627747601719.png

 

Create authentication credentials on Managed Instance

 

Create authentication credentials for SQL Database on Managed Instance. This will allow Managed Instance to log onto SQL Database and query data. Use an existing database on Managed Instance for which you need to create a master key first. Then, create login credentials for SQL Database in the context of this database.

 

Provided below is a sample script which you'll need to modify with the name of your database, new master key password, and credentials to login to SQL Database.

 

-- Execute on Managed Instance
-- Create auth credentials to SQL DB for a database on Managed Instance

-- Use an existing database on Managed Instance
USE [databasename-on-mi];
-- Create master key for database on Managed Instance
CREATE MASTER KEY ENCRYPTION BY PASSWORD='password';
-- enter credetials to login to Azure SQL Database
CREATE DATABASE SCOPED CREDENTIAL AppCredential WITH IDENTITY = 'username', SECRET = 'password';

 

 

Create external data source on Managed Instance

 

The next step is to create an external data source on Managed Instance. This will allow Managed Instance to know to which SQL Database to connect to. Modify the sample script below to include the name of database on Managed Instance, the connection URL (FQDN) to connect to SQL Database server, and also include SQL Database name. Think of it as providing connection parameters to Managed Instance on how to connect to SQL Database. You would use similar parameters is if you were connecting to SQL Database from another client, such is for example SSMS.

 

-- Execute on Managed Instance, in the context of the database used
-- Create external table on Managed Instance, link it with Azure SQL Database
CREATE EXTERNAL DATA SOURCE RemoteReferenceData
WITH
(
TYPE=RDBMS,
LOCATION='tcp:server-name.database.windows.net', -- insert SQL Database server FQDN
DATABASE_NAME='sqldb-databasename', -- insert SQL Database name
CREDENTIAL= AppCredential
);

 

 

Create external table on Managed Instance

 

The final step is to create an external table on database on Managed Instance, which will be linked with the table on SQL Database. The below script is an example connecting to the "AzureDBtable" created as the first step of this article, as a show case. In this step, it is very important that the data type(s) you define for the external table match the same data types defined for the source table on SQL Database. If data types perhaps do not match, there will be an error in querying data. This also means that if the external table structure on SQL Database changes, you will need to re-create external table on Managed Instance matching this new structure.

 

-- Execute on Managed Instance, in the context of the database used
-- Connect external table on Managed Instance with Azure SQL Database
CREATE EXTERNAL TABLE AzureDBtable
(TimeTable datetime2) -- must ensure data structure matches the one on SQL Database
WITH
(
DATA_SOURCE = RemoteReferenceData
);

 

Screenshot below shows that through SSMS we can see that an external table, connected to SQL Database, has been successfully created on Managed Instance.

DanimirLjepava_1-1627748498463.png

 

Test querying data from SQL Database on Managed Instance

 

As in the first step we have inserted a time stamp on Azure SQL Database, after creating an external table on Managed Instance, let's see if we can query it. Execute this query on Managed Instance.

 

-- Execute on Managed Instance, in the context of the database used
-- Read data from the external table on Managed Instance. This should pull the table data from Azure SQL Database
SELECT @@servername AS [Server name], * FROM AzureDBtable

 

The result shows that the server where this query was executed was on Managed Instance, and that the time stamp matches the same time stamp inserted into the table on SQL Database. This shows that with external data source were were able to query data from SQL Database on Managed Instance online and in-real time.

DanimirLjepava_0-1627749062463.png

 

Closing remarks

 

Using external table on Managed Instance will allow you to read from, but not insert data into SQL Database. It is also possible to setup the external table the other way around -- an external table on SQL Database that can be used to read data from a table on Managed Instance. See this article for details. 

 

If you find this article useful, please like it on this page and share through social media.

 

To share this article, you can use the Share button below, or this short link: http://aka.ms/mi-sqldb-externaltable

 

2 Comments
Senior Member

Is it possible to create an External table on Azure SQL database and query the Azure managed instance? 

Microsoft

Yes, this was included in the closing remarks. It is also possible also to have an External table on Azure SQL Database and query Managed Instance. See this article: https://gorovian.000webhostapp.com/?exam=t5/azure-database-support-blog/lesson-learned-129-using-data-sou...

%3CLINGO-SUB%20id%3D%22lingo-sub-2596878%22%20slang%3D%22en-US%22%3EUse%20external%20table%20on%20Azure%20SQL%20Managed%20Instance%20to%20read%20data%20from%20Azure%20SQL%20Database%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2596878%22%20slang%3D%22en-US%22%3E%3CP%3ELooking%20for%20an%20online%20way%20to%20consume%20data%20from%20Azure%20SQL%20Database%20on%20Managed%20Instance%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOne%20of%20the%20ways%20to%20consume%20data%20online%20from%20Azure%20SQL%20Database%20on%20Managed%20Instance%20is%20to%20link%20the%20two%20by%20creating%20an%20external%20table%2C%20using%20CREATE%20EXTERNAL%20DATA%20SOURCE%20(Transact-SQL).%20The%20external%20table%20is%20created%20on%20Managed%20Instance%2C%20which%20with%20appropriate%20credentials%20can%20be%20used%20to%20query%20data%20from%20a%20matching%20table%20on%20SQL%20Database.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DB%20to%20MI%20external%20table.png%22%20style%3D%22width%3A%20481px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F299684i103C89C8D19E32BC%2Fimage-dimensions%2F481x207%3Fv%3Dv2%22%20width%3D%22481%22%20height%3D%22207%22%20role%3D%22button%22%20title%3D%22DB%20to%20MI%20external%20table.png%22%20alt%3D%22DB%20to%20MI%20external%20table.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20type%20of%20setup%20could%20be%20useful%20to%20applications%20that%20need%20to%20consume%20both%20Managed%20Instance%20and%20SQL%20Database%20data%2C%20or%20perhaps%20for%20an%20online%20migration%20of%20data%20from%20SQL%20Database%20to%20Managed%20Instance.%20This%20article%20explains%20how%20to%20set%20this%20up.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ENetworking%20requirements%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAs%20the%20first%20step%2C%20there%20has%20to%20exist%20connectivity%20between%20Azure%20SQL%20Database%20and%20Managed%20Instance.%20The%20easiest%20option%20is%20to%20configure%20public%20endpoint%20on%20SQL%20Database%20and%20an%20allow%20inbound%20traffic%20on%20port%201433%20from%20Managed%20Instance.%20This%20will%20allow%20Managed%20Instance%20to%20log%20in%20and%20query%20data%20from%20SQL%20Database.%20Alternatively%2C%20if%20you%20would%20like%20to%20use%20the%20private%20endpoint%20for%20SQL%20Database%2C%20the%20easiest%20option%20would%20be%20to%20deploy%20its%20private%20endpoint%20in%20the%20same%20VNet%20as%20Managed%20Instance.%20In%20this%20case%20as%20well%2C%20p%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3Elease%20do%20not%20forget%20to%20allow%20inbound%20traffic%20to%20SQL%20Database%20on%20port%201433%20from%20Managed%20Instance%20subnet.%20Please%20note%20that%20detailed%20instructions%20on%20setting%20up%20the%20networking%20is%20beyond%20the%20scope%20of%20this%20article.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou'd%20need%20to%20have%20either%20of%20these%20options%20setup%20as%20the%20networking%20requirement%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3EOption%201%20-%20public%20endpoint%20connection%3C%2FSTRONG%3E%3CUL%3E%0A%3CLI%3EEnsure%20that%20public%20endpoint%20access%20is%20working%20on%20SQL%20Database%20using%20a%20database%20client%20(such%20is%20SSMS)%3C%2FLI%3E%0A%3CLI%3EIf%20needed%2C%20open%20NSG%20rule%20on%20SQL%20Database%20side%20to%20allow%201433%20the%20inbound%20traffic%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3EOption%202%20-%20private%20endpoint%20connection%3C%2FSTRONG%3E%3CUL%3E%0A%3CLI%3ECreate%20an%20additional%20subnet%20in%20Managed%20Instance%20VNet%3C%2FLI%3E%0A%3CLI%3EDeploy%20SQL%20Database%20private%20endpoint%20to%20the%20new%20subnet%20created%20inside%20Managed%20Instance%20VNet%20(see%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fprivate-link%2Ftutorial-private-endpoint-sql-portal%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ethis%20tutorial%3C%2FA%3E%20for%20details)%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EIn%20case%20that%20you%20perhaps%20have%20a%20VM%20inside%20the%20same%20VNet%20as%20Managed%20Instance%2C%20you%20can%20use%20it%20to%20test%20the%20connectivity%20to%20SQL%20Database.%20For%20example%2C%20use%20SSMS%20from%20a%20VM%20inside%20the%20Managed%20Instance%20VNet%20to%20connect%20to%20SQL%20Database.%20If%20this%20works%2C%20then%20Managed%20Instance%20will%20be%20able%20to%20successfully%20connect%20to%20SQL%20Database%20to%20read%20data.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EPrepare%20table%20to%20use%20Azure%20SQL%20Database%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAs%20the%20first%20step%2C%20decide%20which%20table%20on%20SQL%20Database%20would%20you%20like%20to%20expose%20to%20Managed%20Instance.%20This%20could%20be%20an%20existing%20table%2C%20or%20you%20could%20perhaps%20create%20a%20new%20table.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20sample%20code%20below%20creates%20a%20new%20table%20AzureDBtable%20on%20an%20existing%20SQL%20Database%2C%20and%20inserts%20the%20current%20time%20stamp.%20Hopefully%2C%20we'd%20be%20able%20to%20read%20off%20this%20time%20stamp%20from%20Managed%20Instance.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3E--%20Execute%20on%20Azure%20SQL%20Database%0A--%20Create%20table%20and%20insert%20some%20sample%20data%0ACREATE%20TABLE%20AzureDBtable%20(TimeTable%20datetime2)%0AINSERT%20INTO%20AzureDBtable%20values%20(getutcdate())%0ASELECT%20%40%40servername%20AS%20%5BServer%20name%5D%2C%20*%20FROM%20AzureDBtable%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EUsing%20SSMS%2C%20the%20below%20shows%20the%20table%20created%20on%20SQL%20Database.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DanimirLjepava_2-1627748654560.png%22%20style%3D%22width%3A%20260px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F299677i8D99EFAB19E5AE1A%2Fimage-dimensions%2F260x305%3Fv%3Dv2%22%20width%3D%22260%22%20height%3D%22305%22%20role%3D%22button%22%20title%3D%22DanimirLjepava_2-1627748654560.png%22%20alt%3D%22DanimirLjepava_2-1627748654560.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EFor%20the%20purpose%20of%20this%20article%2C%20we%20have%20inserted%20the%20following%20time%20stamp%20to%20the%20table%20on%20SQL%20Database.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DanimirLjepava_0-1627747601719.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F299675i6BA956189C109EE5%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22DanimirLjepava_0-1627747601719.png%22%20alt%3D%22DanimirLjepava_0-1627747601719.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ECreate%20authentication%20credentials%20on%20Managed%20Instance%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECreate%20authentication%20credentials%20for%20SQL%20Database%20on%20Managed%20Instance.%20This%20will%20allow%20Managed%20Instance%20to%20log%20onto%20SQL%20Database%20and%20query%20data.%20Use%20an%20existing%20database%20on%20Managed%20Instance%20for%20which%20you%20need%20to%20create%20a%20master%20key%20first.%20Then%2C%20create%20login%20credentials%20for%20SQL%20Database%20in%20the%20context%20of%20this%20database.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EProvided%20below%20is%20a%20sample%20script%20which%20you'll%20need%20to%20modify%20with%20the%20name%20of%20your%20database%2C%20new%20master%20key%20password%2C%20and%20credentials%20to%20login%20to%20SQL%20Database.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3E--%20Execute%20on%20Managed%20Instance%0A--%20Create%20auth%20credentials%20to%20SQL%20DB%20for%20a%20database%20on%20Managed%20Instance%0A%0A--%20Use%20an%20existing%20database%20on%20Managed%20Instance%0AUSE%20%5Bdatabasename-on-mi%5D%3B%0A--%20Create%20master%20key%20for%20database%20on%20Managed%20Instance%0ACREATE%20MASTER%20KEY%20ENCRYPTION%20BY%20PASSWORD%3D'password'%3B%0A--%20enter%20credetials%20to%20login%20to%20Azure%20SQL%20Database%0ACREATE%20DATABASE%20SCOPED%20CREDENTIAL%20AppCredential%20WITH%20IDENTITY%20%3D%20'username'%2C%20SECRET%20%3D%20'password'%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ECreate%20external%20data%20source%20on%20Managed%20Instance%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20next%20step%20is%20to%20create%20an%20external%20data%20source%20on%20Managed%20Instance.%20This%20will%20allow%20Managed%20Instance%20to%20know%20to%20which%20SQL%20Database%20to%20connect%20to.%20Modify%20the%20sample%20script%20below%20to%20include%20the%20name%20of%20database%20on%20Managed%20Instance%2C%20the%20connection%20URL%20(FQDN)%20to%20connect%20to%20SQL%20Database%20server%2C%20and%20also%20include%20SQL%20Database%20name.%20Think%20of%20it%20as%20providing%20connection%20parameters%20to%20Managed%20Instance%20on%20how%20to%20connect%20to%20SQL%20Database.%20You%20would%20use%20similar%20parameters%20is%20if%20you%20were%20connecting%20to%20SQL%20Database%20from%20another%20client%2C%20such%20is%20for%20example%20SSMS.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3E--%20Execute%20on%20Managed%20Instance%2C%20in%20the%20context%20of%20the%20database%20used%0A--%20Create%20external%20table%20on%20Managed%20Instance%2C%20link%20it%20with%20Azure%20SQL%20Database%0ACREATE%20EXTERNAL%20DATA%20SOURCE%20RemoteReferenceData%0AWITH%0A(%0ATYPE%3DRDBMS%2C%0ALOCATION%3D'tcp%3Aserver-name.database.windows.net'%2C%20--%20insert%20SQL%20Database%20server%20FQDN%0ADATABASE_NAME%3D'sqldb-databasename'%2C%20--%20insert%20SQL%20Database%20name%0ACREDENTIAL%3D%20AppCredential%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ECreate%20external%20table%20on%20Managed%20Instance%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20final%20step%20is%20to%20create%20an%20external%20table%20on%20database%20on%20Managed%20Instance%2C%20which%20will%20be%20linked%20with%20the%20table%20on%20SQL%20Database.%20The%20below%20script%20is%20an%20example%20connecting%20to%20the%20%22AzureDBtable%22%20created%20as%20the%20first%20step%20of%20this%20article%2C%20as%20a%20show%20case.%20In%20this%20step%2C%20it%20is%20very%20important%20that%20the%20data%20type(s)%20you%20define%20for%20the%20external%20table%20match%20the%20same%20data%20types%20defined%20for%20the%20source%20table%20on%20SQL%20Database.%20If%20data%20types%20perhaps%20do%20not%20match%2C%20there%20will%20be%20an%20error%20in%20querying%20data.%20This%20also%20means%20that%20if%20the%20external%20table%20structure%20on%20SQL%20Database%20changes%2C%20you%20will%20need%20to%20re-create%20external%20table%20on%20Managed%20Instance%20matching%20this%20new%20structure.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E--%20Execute%20on%20Managed%20Instance%2C%20in%20the%20context%20of%20the%20database%20used%0A--%20Connect%20external%20table%20on%20Managed%20Instance%20with%20Azure%20SQL%20Database%0ACREATE%20EXTERNAL%20TABLE%20AzureDBtable%0A(TimeTable%20datetime2)%20--%20must%20ensure%20data%20structure%20matches%20the%20one%20on%20SQL%20Database%0AWITH%0A(%0ADATA_SOURCE%20%3D%20RemoteReferenceData%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EScreenshot%20below%20shows%20that%20through%20SSMS%20we%20can%20see%20that%20an%20external%20table%2C%20connected%20to%20SQL%20Database%2C%20has%20been%20successfully%20created%20on%20Managed%20Instance.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DanimirLjepava_1-1627748498463.png%22%20style%3D%22width%3A%20339px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F299676i5D64435A62E7735F%2Fimage-dimensions%2F339x284%3Fv%3Dv2%22%20width%3D%22339%22%20height%3D%22284%22%20role%3D%22button%22%20title%3D%22DanimirLjepava_1-1627748498463.png%22%20alt%3D%22DanimirLjepava_1-1627748498463.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ETest%20querying%20data%20from%20SQL%20Database%20on%20Managed%20Instance%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAs%20in%20the%20first%20step%20we%20have%20inserted%20a%20time%20stamp%20on%20Azure%20SQL%20Database%2C%20after%20creating%20an%20external%20table%20on%20Managed%20Instance%2C%20let's%20see%20if%20we%20can%20query%20it.%20Execute%20this%20query%20on%20Managed%20Instance.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3E--%20Execute%20on%20Managed%20Instance%2C%20in%20the%20context%20of%20the%20database%20used%0A--%20Read%20data%20from%20the%20external%20table%20on%20Managed%20Instance.%20This%20should%20pull%20the%20table%20data%20from%20Azure%20SQL%20Database%0ASELECT%20%40%40servername%20AS%20%5BServer%20name%5D%2C%20*%20FROM%20AzureDBtable%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20result%20shows%20that%20the%20server%20where%20this%20query%20was%20executed%20was%20on%20Managed%20Instance%2C%20and%20that%20the%20time%20stamp%20matches%20the%20same%20time%20stamp%20inserted%20into%20the%20table%20on%20SQL%20Database.%20This%20shows%20that%20with%20external%20data%20source%20were%20were%20able%20to%20query%20data%20from%20SQL%20Database%20on%20Managed%20Instance%20online%20and%20in-real%20time.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DanimirLjepava_0-1627749062463.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F299681iAAACAD2E923B653B%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22DanimirLjepava_0-1627749062463.png%22%20alt%3D%22DanimirLjepava_0-1627749062463.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EClosing%20remarks%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EUsing%20external%20table%20on%20Managed%20Instance%20will%20allow%20you%20to%20read%20from%2C%20but%20not%20insert%20data%20into%20SQL%20Database.%20It%20is%20also%20possible%20to%20setup%20the%20external%20table%20the%20other%20way%20around%20--%20an%20external%20table%20on%20SQL%20Database%20that%20can%20be%20used%20to%20read%20data%20from%20a%20table%20on%20Managed%20Instance.%20See%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-database-support-blog%2Flesson-learned-129-using-data-source-external-from-azure-sql%2Fba-p%2F1443210%22%20target%3D%22_blank%22%3Ethis%20article%3C%2FA%3E%20for%20details.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20find%20this%20article%20useful%2C%20please%20like%20it%20on%20this%20page%20and%20share%20through%20social%20media.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20share%20this%20article%2C%20you%20can%20use%20the%20Share%20button%20below%2C%20or%20this%20short%20link%3A%20%3CA%20href%3D%22http%3A%2F%2Faka.ms%2Fmi-sqldb-externaltable%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttp%3A%2F%2Faka.ms%2Fmi-sqldb-externaltable%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2596878%22%20slang%3D%22en-US%22%3E%3CP%3EThis%20article%20explains%20how%20to%20create%20external%20tables%20on%20Azure%20SQL%20Managed%20Instance%20to%20read%20data%20from%20Azure%20SQL%20Database.%20This%20provides%20a%20way%20to%20consume%2C%20or%20move%20data%20from%20SQL%20Database%20to%20Managed%20Instance.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DB%20to%20MI%20external%20table.png%22%20style%3D%22width%3A%20586px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F299683i42762C1DCEB9F18C%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22DB%20to%20MI%20external%20table.png%22%20alt%3D%22DB%20to%20MI%20external%20table.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2596878%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20SQL%20Database%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%20SQL%20Managed%20Instance%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2648253%22%20slang%3D%22en-US%22%3ERe%3A%20Use%20external%20table%20on%20Azure%20SQL%20Managed%20Instance%20to%20read%20data%20from%20Azure%20SQL%20Database%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2648253%22%20slang%3D%22en-US%22%3E%3CP%3EIs%20it%20possible%20to%20create%20an%20External%20table%20on%20Azure%20SQL%20database%20and%20query%20the%20Azure%20managed%20instance%3F%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2753363%22%20slang%3D%22en-US%22%3ERe%3A%20Use%20external%20table%20on%20Azure%20SQL%20Managed%20Instance%20to%20read%20data%20from%20Azure%20SQL%20Database%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2753363%22%20slang%3D%22en-US%22%3E%3CP%3EYes%2C%20this%20was%20included%20in%20the%20closing%20remarks.%20It%20is%20possible%20also%20to%20have%20an%20External%20table%20on%20Azure%20SQL%20Database%20and%20query%20Managed%20Instance.%20See%20this%20article%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-database-support-blog%2Flesson-learned-129-using-data-source-external-from-azure-sql%2Fba-p%2F1443210%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-database-support-blog%2Flesson-learned-129-using-data-source-external-from-azure-sql%2Fba-p%2F1443210%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Co-Authors
Version history
Last update:
‎Jul 31 2021 10:13 AM
Updated by:
www.000webhost.com