How do you create a view with SNAPSHOT_MATERIALIZATION in SQL Server 2017?
You can't. The feature is disabled in 2017 RTM.



That said, you can...

Using AdventureWorks:

CREATE VIEW dbo.TH
WITH SCHEMABINDING
AS
SELECT P.ProductID, COUNT_BIG(*) AS cbs
FROM Production.Product AS P
JOIN Production.TransactionHistory AS TH
    ON TH.ProductID = P.ProductID
GROUP BY P.ProductID;
GO
CREATE UNIQUE CLUSTERED INDEX cuq ON dbo.TH (ProductID)
WITH (SNAPSHOT_MATERIALIZATION = ON);


Changes to the underlying tables are not immediately reflected in the view (as is normally the case with SQL Server). Likewise, data modifications against the underlying tables do not have to maintain the snapshot indexed view.

To refresh the view contents, one needs to call one of the new stored procedures:

EXECUTE sys.sp_refresh_single_snapshot_view
    @view_name = N'dbo.TH',
    @rgCode = 0; -- don't know what this is for yet


This produces the execution plan:



This likely won't work for you, because either an undocumented trace flag is needed, or you need to do the particularly nasty thing I did: writing to the memory location holding the feature flag (using a debugger) to enable this feature.

If you're curious, the feature flag is the byte at sqllang!g_featureSwitchesLangSvc+0x10f. It is checked during sqllang!SpRefreshSingleSnapshotView.

If you want to play along, and are fully prepared to accept the consequences of hacking about in SQL Server's code while it is running, and using a feature that Microsoft does not think is ready yet:


Attach a debugger to the SQL Server 2017 process. I use WinDbg.
Set a breakpoint:

bp sqllang!SpRefreshSingleSnapshotView

Resume SQL Server using the Go command (g)
Create the view above, but not the unique clustered index yet
Run the sys.sp_refresh_single_snapshot_view command above
When the breakpoint is hit, step through until you see the code line:

cmp byte ptr [sqllang!g_featureSwitchesLangSvc+0x10f (00007fff`328dfbcf)],0


The offset may be different in other builds, for example in 2017 RTM CU3 it is sqllang!g_featureSwitchesLangSvc+0x114
The memory address inside the parentheses may be different. Use the one you see.
Use the display memory command to see the current value at the memory address you found:

db 00007fff`328dfbcf L1

This should show a zero, indicating that the feature is disabled.
Change the zero to a one, using the enter values command (again with your memory address):

eb 00007fff`328dfbcf 1

Disable the breakpoint and resume running SQL Server.
The feature is now enabled.
Build the unique clustered index on the view.
Play around.




Note SNAPSHOT_MATERIALIZATION allows us to materialize a snapshot of a query specification that ordinarily could not be indexed, for example the below uses MAX:

CREATE VIEW dbo.TH2
WITH SCHEMABINDING
AS
SELECT TH.ProductID, MaxTransactionID = MAX(TH.TransactionID)
FROM Production.TransactionHistory AS TH
GROUP BY TH.ProductID;
GO
CREATE UNIQUE CLUSTERED INDEX cuq ON dbo.TH2 (ProductID)
WITH (SNAPSHOT_MATERIALIZATION = ON);


Result:

Commands completed successfully.