Serverless SQL Examples for Azure Synapse Analytics¶
Home > Code Examples > Serverless SQL
This section provides examples and best practices for working with Serverless SQL pools in Azure Synapse Analytics. Serverless SQL pools allow you to query data directly from your data lake storage without the need for data movement or pre-loading.
Available Examples¶
Performance Optimization¶
- Query Optimization - Techniques to optimize serverless SQL queries
- File format selection
- Column pruning
- Predicate pushdown
- Partition elimination
- External tables and statistics
- Resource management
Coming Soon¶
- External Tables Management - Best practices for creating and maintaining external tables
- Complex Query Patterns - Solutions for common analytical query scenarios
- Security and Access Control - Row-level security and column-level access
- Data Virtualization - Creating logical data warehouses using views and stored procedures
Why Serverless SQL in Azure Synapse?¶
Serverless SQL pools in Azure Synapse Analytics offer several benefits:
- Pay-per-Query: Only pay for the data processed during query execution
- No Infrastructure Management: Eliminates the need to provision or scale resources
- Built-in Security: Seamless integration with Azure AD and role-based access control
- Data Exploration: Efficiently query and analyze data in various formats
- Integration with BI Tools: Connect with PowerBI and other visualization tools
Serverless SQL Architecture Patterns¶
Serverless SQL in Azure Synapse Analytics supports several architecture patterns:
- Data Lake Query Engine: Direct querying of files in storage
- Data Virtualization Layer: Creating views and stored procedures over external data
- Hybrid Architecture: Combining serverless SQL with dedicated SQL pools
- Logical Data Warehouse: Federated queries across multiple data sources
Code Example: Basic Serverless SQL Query¶
-- Query CSV files directly
SELECT TOP 100 *
FROM OPENROWSET(
BULK 'https://mydatalake.blob.core.windows.net/data/sales/*.csv',
FORMAT = 'CSV',
PARSER_VERSION = '2.0',
HEADER_ROW = TRUE
) AS [sales]
WHERE [sales].[Region] = 'North America'
ORDER BY [sales].[OrderDate];
-- Create an external table
CREATE EXTERNAL TABLE Sales (
OrderID INT,
OrderDate DATE,
Region VARCHAR(50),
Product VARCHAR(100),
Quantity INT,
UnitPrice DECIMAL(10,2),
TotalAmount DECIMAL(10,2)
)
WITH (
LOCATION = 'sales/*.csv',
DATA_SOURCE = MyDataLake,
FILE_FORMAT = CsvFormat
);
-- Query the external table
SELECT
Region,
SUM(TotalAmount) AS RegionalSales
FROM Sales
GROUP BY Region
ORDER BY RegionalSales DESC;
Related Resources¶
- Serverless SQL Guide - Comprehensive guide to Serverless SQL
- Serverless SQL Architecture - Reference architecture
- Performance Best Practices - Performance optimization tips
- Azure Synapse Analytics Documentation
- T-SQL Reference for Serverless SQL Pools
