sqlsql-serverazureazure-sql-database

Materialized view in Marketing Performance DB in Azure SQL database


I want to create a materialized view in a marketing performance database but am getting an error while trying to create .

Using below query to create

CREATE MATERIALIZED VIEW InvoicesTempM  
WITH (distribution = hash(Invoiceid), FOR_APPEND)  
AS
SELECT Invoiceid, COMPANY from dbo.Invoices

Getting error as below:

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'CREATE MATERIALIZED VIEW'.
Completion time: 2023-02-09T10:23:12.8418869+05:30

Could anyone help here how can we create materialized view in Azure SQL database, if we cannot please share if there is any alternatives?


Solution

  • MATERIALIZED VIEW are a concept invented by Oracle. The closest topic in Microsoft SQL Server are INDEXED VIEW, that is :

    In MS SQL Server all Indexed Views are alwyas synchronized with source data (do not need to refresh).

    Refer to "Create indexed views"