Skip to content

Commit 68ecab3

Browse files
authored
Merge pull request #3651 from bwiggin10/query_store_PR
Add Query Store Parameter to sp_ineachdb
2 parents d5173ea + 470d551 commit 68ecab3

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

sp_ineachdb.sql

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ ALTER PROCEDURE [dbo].[sp_ineachdb]
2929
@Version varchar(30) = NULL OUTPUT,
3030
@VersionDate datetime = NULL OUTPUT,
3131
@VersionCheckMode bit = 0,
32-
@is_ag_writeable_copy bit = 0
32+
@is_ag_writeable_copy bit = 0,
33+
@is_query_store_on bit = 0
3334
-- WITH EXECUTE AS OWNER – maybe not a great idea, depending on the security of your system
3435
AS
3536
BEGIN
@@ -235,6 +236,23 @@ OPTION (MAXRECURSION 0);
235236
)
236237
);
237238

239+
-- delete any databases that don't match query store criteria
240+
IF @SQLVersion >= 13
241+
BEGIN
242+
DELETE dbs FROM #ineachdb AS dbs
243+
WHERE EXISTS
244+
(
245+
SELECT 1
246+
FROM sys.databases AS d
247+
WHERE d.database_id = dbs.id
248+
AND NOT
249+
(
250+
is_query_store_on = COALESCE(@is_query_store_on, is_query_store_on)
251+
AND NOT (@is_query_store_on = 1 AND d.database_id = 3) OR (@is_query_store_on = 0 AND d.database_id = 3) -- Excluding the model database which shows QS enabled in SQL2022+
252+
)
253+
);
254+
END
255+
238256
-- if a user access is specified, remove any that are NOT in that state
239257
IF @user_access IN (N'SINGLE_USER', N'MULTI_USER', N'RESTRICTED_USER')
240258
BEGIN

0 commit comments

Comments
 (0)