SQL Server provides advanced features to integrate and manage big data and distributed data sources. Two prominent features are PolyBase and Stretch Database.
PolyBase allows us to access and query data from external data sources such as Azure SQL Data Warehouse, Hadoop, and Oracle. We can use T-SQL to query data from these sources as if they were part of our SQL Server database. PolyBase enables SQL Server to act as a federated engine, where it can query data stored outside of SQL Server without needing to move the data into SQL Server.
To use PolyBase, we will need to configure the PolyBase services and create the required database objects such as external data sources, external tables, and definitions. Here is an example of querying data from Hadoop using PolyBase:
CREATE EXTERNAL DATA SOURCE Hadoop
WITH (LOCATION = 'hdfs://myhadoopcluster:9000');
CREATE EXTERNAL TABLE HadoopTable (
[col1] INT,
[col2] NVARCHAR(50),
[col3] FLOAT
) WITH (
LOCATION = '/path/to/hadoop/folder',
DATA_SOURCE = Hadoop
);
SELECT col1, col2, col3
FROM HadoopTable
WHERE col1 > 10;
Stretch Database is another feature that allows us to stretch our on-premises data to Azure, improving the performance of our queries that involve large amounts of historical data. When we stretch our data to Azure, SQL Server maintains a link between the local and remote data using a SQL Server database as a logical bridge.
Stretch Database allows us to store historical data in the cloud while keeping more frequently used data on premises, improving the performance of the local queries while keeping the historical data available. We can use Stretch Database on selected tables to offload them to Azure based on a certain condition, such as data that is older than a certain date. We can also pause or resume data migration to optimize our workloads.
To use Stretch Database, we need to configure it in SQL Server and identify the tables that are suitable for stretching. Here is an example of enabling Stretch Database for a table:
ALTER TABLE SalesData
ENABLE REMOTE_DATA_ARCHIVE
WITH (MIGRATION_STATE = ON);
In conclusion, PolyBase and Stretch Database are advanced features in SQL Server that can be used to integrate and manage big data and distributed data sources. Both features require configuring SQL Server and creating required database objects to function correctly.