Skip to content
Learn — Azure analytics reference library covering services, architecture patterns, tutorials, solutions, monitoring, DevOps

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:

  1. Pay-per-Query: Only pay for the data processed during query execution
  2. No Infrastructure Management: Eliminates the need to provision or scale resources
  3. Built-in Security: Seamless integration with Azure AD and role-based access control
  4. Data Exploration: Efficiently query and analyze data in various formats
  5. 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:

Azure Synapse SQL Architecture

  1. Data Lake Query Engine: Direct querying of files in storage
  2. Data Virtualization Layer: Creating views and stored procedures over external data
  3. Hybrid Architecture: Combining serverless SQL with dedicated SQL pools
  4. 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;