patternsqlMinor
Linked Server alternative in Sql Azure database
Viewed 0 times
alternativesqldatabaseazureserverlinked
Problem
We are migrating database from Rackspace to Azure. Our databases were deployed on Virtual Machines in rackspace. In our queries we are using Linked server to other databases. Basically cross database query.
problem is that after migrating databases, we are unable to use linked server queries as Sql Azure db does not supports Linked Servers.
Kindly help.
UPDATE:
-
Not all databases are in azure. Some databases are with their respective owners in remote locations. We need to query database that are running outside Azure.
-
There's no VM for Sql Server in Azure. We are using Database as a service in Azure.
See the image below for more details
problem is that after migrating databases, we are unable to use linked server queries as Sql Azure db does not supports Linked Servers.
Kindly help.
UPDATE:
-
Not all databases are in azure. Some databases are with their respective owners in remote locations. We need to query database that are running outside Azure.
-
There's no VM for Sql Server in Azure. We are using Database as a service in Azure.
See the image below for more details
Solution
You can use cross database queries as explained here. For example, to make reference to a remote table on a query you need to create a data source:
Define an external table using that data source.
Finally, use the external table on SELECT statements.
CREATE EXTERNAL DATA SOURCE MyExtSrc
WITH
(
TYPE=SHARD_MAP_MANAGER,
LOCATION='myserver.database.windows.net',
DATABASE_NAME='ShardMapDatabase',
CREDENTIAL= SMMUser,
SHARD_MAP_NAME='ShardMap'
);Define an external table using that data source.
CREATE EXTERNAL TABLE [dbo].[all_dm_exec_requests](
[session_id] smallint NOT NULL,
[request_id] int NOT NULL,
[start_time] datetime NOT NULL,
[status] nvarchar(30) NOT NULL,
[command] nvarchar(32) NOT NULL,
[sql_handle] varbinary(64),
[statement_start_offset] int,
[statement_end_offset] int,
[cpu_time] int NOT NULL
)
WITH
(
DATA_SOURCE = MyExtSrc,
SCHEMA_NAME = 'sys',
OBJECT_NAME = 'dm_exec_requests',
DISTRIBUTION=ROUND_ROBIN
);Finally, use the external table on SELECT statements.
SELECT TOP 10
[request_id],
[start_time]
[status],
[command]
FROM all_dm_exec_requests
ORDER BY [cpu_time] DESCCode Snippets
CREATE EXTERNAL DATA SOURCE MyExtSrc
WITH
(
TYPE=SHARD_MAP_MANAGER,
LOCATION='myserver.database.windows.net',
DATABASE_NAME='ShardMapDatabase',
CREDENTIAL= SMMUser,
SHARD_MAP_NAME='ShardMap'
);CREATE EXTERNAL TABLE [dbo].[all_dm_exec_requests](
[session_id] smallint NOT NULL,
[request_id] int NOT NULL,
[start_time] datetime NOT NULL,
[status] nvarchar(30) NOT NULL,
[command] nvarchar(32) NOT NULL,
[sql_handle] varbinary(64),
[statement_start_offset] int,
[statement_end_offset] int,
[cpu_time] int NOT NULL
)
WITH
(
DATA_SOURCE = MyExtSrc,
SCHEMA_NAME = 'sys',
OBJECT_NAME = 'dm_exec_requests',
DISTRIBUTION=ROUND_ROBIN
);SELECT TOP 10
[request_id],
[start_time]
[status],
[command]
FROM all_dm_exec_requests
ORDER BY [cpu_time] DESCContext
StackExchange Database Administrators Q#181679, answer score: 3
Revisions (0)
No revisions yet.