HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMinor

Can I have 'Query Store' automatically on when I create new databases?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
cannewcreatedatabasesautomaticallyquerystorewhenhave

Problem

Query Store is available in SQL Server 2016+ and on Azure SQL DB it is on by default. With an on-premises SQL Server, it has to be started on each database individually.

Is there a way I can have Query Store on by default when new databases are created?

Solution

Query Store is not active for new databases by default.

If you turn it on for model database, it will be on for any new databases you create in the same instance. I tested in SQL 2017.

To turn it on in model database run following:

ALTER DATABASE model SET QUERY_STORE = ON;


I suggest you read this article and decide if you want to turn it on for all databases and settings you want to modify.

Best Practice with the Query Store

Code Snippets

ALTER DATABASE model SET QUERY_STORE = ON;

Context

StackExchange Database Administrators Q#196258, answer score: 9

Revisions (0)

No revisions yet.