Index Tuning Report – RockyPC / SQLStorm – 2026-11-09

Tuning goal: Index Tuning

Server: RockyPC · SQL Server 2025 (17.x), Enterprise Developer Edition · Database: SQLStorm · Product version: 17.0.1145.4 RTM-GDR

High-confidence index opportunities Enterprise feature set Usage window: 3.9 days No forced-plan failures

Executive summary

The strongest actionable opportunities are on dbo.PostHistory, dbo.Votes, and dbo.Comments. The missing-index evidence shows high estimated impact, while existing indexes on the same tables are keyed on different columns. The recommended additions are deliberately consolidated to avoid creating every overlapping missing-index candidate.

99.61%reported impact for the PostHistory(PostId) suggestion
847,593rows in dbo.PostHistory
926,084rows in dbo.Votes
111.3 MBestimated size of the three primary new indexes
  1. Priority 1: Add a consolidated covering index on dbo.PostHistory keyed by PostId, CreationDate, PostHistoryTypeId, including the narrow sampled portion of Comment. Estimated size: 45.3 MB for 847,593 rows, based on the reported overlap candidate.
  2. Priority 2: Add dbo.PostHistory(CreationDate, UserId) including Comment. Estimated size: 32.3 MB for 847,593 rows, based on the reported candidate.
  3. Priority 3: Add dbo.Votes(UserId) including VoteTypeId, BountyAmount. Estimated size: 28.3 MB for 926,084 rows, based on the reported candidate.
  4. Priority 4: Add dbo.Comments(PostId). Estimated size: 5.4 MB for 351,440 rows, based on the reported candidate and 291 total seeks/scans.
  5. Priority 5: Re-trust the 17 reported foreign keys after conditional validation. Untrusted foreign keys prevent join elimination and predicate pruning.
  6. Priority 6: Enable automatic and asynchronous statistics maintenance. Both automatic statistics creation and update are currently disabled.
Important observation: index and plan statistics cover only 3.9 days, from 2026-11-05 09:45:22. This is sufficient to prioritize additions supported by high-impact missing-index recommendations, but it is too short to justify dropping low-use indexes. No drops are recommended.

Scope and evidence

AreaFindingInterpretation
PlatformSQL Server 2025, Enterprise Developer Edition; online operations, page compression, columnstore, CE feedback, DOP feedback, and OPPO availableAdvanced index operations are available, but workload evidence should determine whether they are appropriate.
Usage period3.9 days since the latest database startupUsage counts are not representative of monthly or quarterly activity.
WritesIndex usage statistics show updates of 0 for listed indexes; operational hotspot leaf operations also show 0Observed write overhead is currently low, but the short collection period limits confidence.
Large-table thresholdNo table is reported as larger than 1,000,000 rows; the largest shown are Votes at 926,084 and PostHistory at 847,593No columnstore recommendation is made. These tables are close to, but below, the requested threshold and have no reported write mix beyond 14 INSERT executions in Query Store.
Index overlapNo duplicate or left-prefix overlapping indexes detectedNo existing index can be safely dropped or merged under the supplied dependency and redundancy evidence.
Recommended index coverage map The diagram shows workload relationships from users and posts to votes, comments, and post history, with recommended access paths highlighted in teal. dbo.Posts dbo.Comments dbo.PostHistory dbo.Votes dbo.Users PostId PostId / dates / type PostId
Recommended access paths concentrate on the join and filter columns most frequently represented in the missing-index and Query Store evidence.

Detailed prioritized recommendations

1. Add a consolidated PostHistory access path

Recommendation: create a page-compressed nonclustered index on dbo.PostHistory(PostId, CreationDate, PostHistoryTypeId) including Comment.

This consolidates the reported PostId, PostId + CreationDate, and PostId + CreationDate + PostHistoryTypeId candidates. It also supports queries joining post history to posts and filtering history type 10 or 11. The supplied average Comment width is only 32 bytes despite the declared varchar(800); the estimate is 45.3 MB. The column is not a large object, so including it is reasonable for the reported candidate.

Evidence: the PostId suggestion reports 99.61% average impact and 55 total seeks/scans; the more selective composite suggestion reports 84.31% average impact. The existing clustered primary key is on Id and does not provide this access path.

Confidence: High for the access path; medium for exact runtime benefit because the usage window is only 3.9 days.

2. Add a date and user access path for PostHistory

Recommendation: create dbo.PostHistory(CreationDate, UserId) including Comment, page compressed. Estimated size: 32.3 MB for 847,593 rows, using the reported overlap candidate.

This serves the missing-index recommendation with 15 total seeks/scans and 52.41% average impact. It is intentionally separate from the PostId-leading index because CreationDate is not a leading key in the first index and the workload includes date-oriented history reporting.

Confidence: Medium-high. The recommendation is supported by a direct missing-index signal, but its lower total seek/scan count warrants a lower priority than the PostId-leading index.

3. Add a user-centered covering index on Votes

Recommendation: create dbo.Votes(UserId) including VoteTypeId, BountyAmount, page compressed. Estimated size: 28.3 MB for 926,084 rows.

The reported recommendation has 99.51% average impact and 15 total seeks/scans. It directly supports the many user aggregation statements in plan cache and Query Store, including the statement identified by query hash FE52206CED094538, which averaged 10,843,182 CPU time units and 236,115 logical reads over two executions in the plan-cache period.

The existing IX_Votes_PostId_VoteType is useful for post-centered access and should remain. It does not cover the leading UserId access pattern.

Confidence: High for user aggregation workloads; medium for total production benefit because writes and usage are observed for only 3.9 days.

4. Add the missing Comments foreign-key access path

Recommendation: create dbo.Comments(PostId), page compressed. Estimated size: 5.4 MB for 351,440 rows.

The missing-index report records 291 total seeks/scans and 36.79% average impact. Query Store statements repeatedly join comments by PostId, including the workload with query text beginning WITH PostStats AS (... LEFT JOIN Comments c ON p.Id = c.PostId ...).

Confidence: High. The index is narrow, inexpensive relative to the 78.1 MB clustered table, and supports a high-frequency join column.

5. Consider a filtered Badges index for the rare Class = 1 workload

Recommendation: add a filtered index on dbo.Badges(UserId) including Id with the predicate Class = 1. The histogram reports Class 1 at 2.30% of 439,352 rows. This is the exception to avoiding an unfiltered low-cardinality leading key: the predicate is selective and literal in the observed Query Store workload.

The existing IX_Badges_UserId_Id is heavily used, with 216 seeks and 233 scans, and is only 4.6 MB. Therefore this filtered index is optional rather than mandatory. A filtered index is reliably matched when the query contains the literal predicate or is recompiled; parameterized predicates may not use it unless the optimizer can prove the parameter value satisfies the filter.

Estimated size: the input does not provide a filtered-candidate size. A firm MB estimate is therefore unavailable; it should be materially below the 4.6 MB unfiltered index because the filter retains approximately 2.30% of the reported histogram rows. This is a medium-confidence optimization and should be deferred until the rare-Class-1 queries are confirmed as important.

6. Re-trust foreign keys after conditional validation

All 17 reported foreign keys are enabled but not trusted. An untrusted constraint blocks optimizer join elimination and predicate pruning. The script in the Scripts section checks each relationship and re-trusts it only when no violating rows exist; otherwise it prints the skipped constraint name. The validation scans may be expensive on large tables.

Confidence: High for optimizer correctness and plan quality; the performance effect depends on the individual query plans.

Workload and query findings

Plan cache and Query Store

The plan cache contains several expensive analytical statements. The most prominent supplied example is query hash FE52206CED094538, with two executions, average CPU time 10,843,182, and average logical reads 236,115. Query hash 4BC12F83CC42755C averaged 4,499,350 CPU time units and 32,006 logical reads over one execution. These statements aggregate Votes by UserId and PostHistory by PostId, making the recommended indexes directly relevant.

Query Store shows repeated workloads with average durations ranging from 8,213.10 ms to 305,882.24 ms over the last seven days. The highest supplied Query Store duration is 305,882.24 ms over five executions, with 8,494,661 average reads and 42 average writes. Query Store reports actual rows of 0 for several statements, so those row figures should not be interpreted as proof that the statements returned no data; they may reflect the captured execution state.

Several workloads contain Posts.Tags LIKE '%' + Tags.TagName + '%'. A conventional index on Tags cannot seek through a leading wildcard. The appropriate improvement is data-model or search design work, such as normalized tag relationships or full-text/search infrastructure; no executable change is recommended here because the required schema and workload details are not supplied.

Sargability

No non-sargable predicates were found in the top 50 plan-cache statements. The Query Store text contains expressions such as ISNULL, COALESCE, CASE, and date expressions in projections and aggregations, but the supplied analysis does not identify them as column-wrapping predicates in scans or filters. No predicate rewrite is recommended from this evidence.

Columnstore assessment

No columnstore index is recommended. The supplied large-table section reports no tables above 1,000,000 rows, while the largest reported tables are dbo.Votes at 926,084 rows and dbo.PostHistory at 847,593 rows. Query Store reports 14 INSERT executions in the last seven days, but there is not enough evidence to justify the maintenance and delta-store behavior of a columnstore design below the requested threshold.

Maintenance and design findings

  • No heap issue: no large heaps and no forwarded-record findings were reported. Consequently, no clustered-index or heap-rebuild recommendation is needed.
  • No duplicate-index drops: no duplicate or left-prefix overlaps were detected, and all four checked nonclustered indexes have no listed dependencies. Nevertheless, the usage period is too short for low-use drops, and no low-use drop is justified.
  • No low-density rebuild: all supplied indexes have average page density of at least 93.65%, well above the approximately 75% review threshold. Rebuilds, fill-factor changes, and page-split remediation are not justified.
  • Current compression: the large existing indexes are already page compressed, including the 820.3 MB clustered PostHistory index, the 400.3 MB clustered Posts index, and the 78.1 MB clustered Comments index. New indexes should use page compression consistently.
  • Foreign-key coverage: the relationships are present, but their untrusted state reduces optimizer usefulness. Re-trusting is preferred over adding redundant foreign-key indexes unless a specific workload demonstrates the need.

Database settings and feedback

Statistics settings

AUTO_CREATE_STATISTICS, AUTO_UPDATE_STATISTICS, and asynchronous statistics updates are all reported as disabled. This is a material risk for the new indexes and the analytical workload. Enable automatic statistics creation and update first, then enable asynchronous update and low-priority waiting as separate database changes. The scripts are separate so a rejected or deferred setting does not prevent the others from being applied.

Automatic tuning

FORCE_LAST_GOOD_PLAN is already desired and active. No change is required. The Enterprise Developer edition supports the option, but enabling it again would be unnecessary.

Cardinality estimation feedback

CE feedback can run: CE feedback is ON, compatibility level is 170, and Query Store is READ_WRITE. CE feedback for expressions is also ON, and no feedback rows are currently reported. Do not force plans or add query hints merely from this report because those actions can prevent CE feedback from adjusting estimates for the affected query. When expression feedback is available, its protection checks cardinality estimates rather than runtime; automatic plan correction remains the mechanism for runtime regressions, and it is already enabled here.

Degree of parallelism feedback

DOP feedback is ON and can run under compatibility level 170 with Query Store READ_WRITE. No DOP feedback rows are reported. It may lower inefficient parallelism, but it does not recompile plans and does not increase DOP above MAXDOP. No MAXDOP hint is recommended because a query or Query Store MAXDOP hint would make that statement ineligible for DOP feedback.

Optional parameter plan optimization

OPPO is active at compatibility level 170 with OPTIONAL_PARAMETER_OPTIMIZATION ON. No catch-all query rewrite is recommended. OPPO can generate a seek-capable non-NULL variant for predicates such as (@p IS NULL OR Column = @p); an index should not be dropped solely because it had no seeks before OPPO was active.

Storage impact

ChangeRowsEstimated sizeBasis and assumptions
Create IX_PostHistory_PostId_CreationDate_Type847,59345.3 MBReported overlap candidate with keys PostId, CreationDate, PostHistoryTypeId and Comment included; page compression requested.
Create IX_PostHistory_CreationDate_UserId847,59332.3 MBReported overlap candidate with keys CreationDate, UserId and Comment included; page compression requested.
Create IX_Votes_UserId_Cover926,08428.3 MBReported overlap candidate with UserId key and VoteTypeId, BountyAmount included; page compression requested.
Create IX_Comments_PostId351,4405.4 MBReported overlap candidate with PostId key; page compression requested.
Create optional filtered IX_Badges_Class1_UserIdApproximately 2.30% of 439,352 histogram rowsNot available from inputNo filtered candidate size was reported; the estimate must be obtained from the actual build.

Estimated net change for mandatory additions: approximately 111.3 MB added from the four reported candidates. No index storage is reclaimed because no drops are recommended. If the optional filtered Badges index is created, the net increase is 111.3 MB plus its unreported filtered size.

Scripts

1. Enable automatic statistics creation

USE [SQLStorm];
GO

ALTER DATABASE [SQLStorm] SET AUTO_CREATE_STATISTICS ON;
GO

2. Enable automatic statistics updates

USE [SQLStorm];
GO

ALTER DATABASE [SQLStorm] SET AUTO_UPDATE_STATISTICS ON;
GO

3. Enable asynchronous statistics updates

USE [SQLStorm];
GO

ALTER DATABASE [SQLStorm] SET AUTO_UPDATE_STATISTICS_ASYNC ON;
GO

4. Allow low-priority waiting for asynchronous statistics updates

USE [SQLStorm];
GO

ALTER DATABASE SCOPED CONFIGURATION SET ASYNC_STATS_UPDATE_WAIT_AT_LOW_PRIORITY = ON;
GO

5. Create the consolidated PostHistory index

USE [SQLStorm];
GO

IF NOT EXISTS
(
    SELECT 1
    FROM sys.indexes
    WHERE object_id = OBJECT_ID(N'dbo.PostHistory')
      AND name = N'IX_PostHistory_PostId_CreationDate_Type'
)
BEGIN
    CREATE NONCLUSTERED INDEX [IX_PostHistory_PostId_CreationDate_Type]
    ON [dbo].[PostHistory] ([PostId], [CreationDate], [PostHistoryTypeId])
    INCLUDE ([Comment])
    WITH
    (
        DATA_COMPRESSION = PAGE,
        ONLINE = ON,
        SORT_IN_TEMPDB = ON
    );
END;
GO

6. Create the PostHistory date and user index

USE [SQLStorm];
GO

IF NOT EXISTS
(
    SELECT 1
    FROM sys.indexes
    WHERE object_id = OBJECT_ID(N'dbo.PostHistory')
      AND name = N'IX_PostHistory_CreationDate_UserId'
)
BEGIN
    CREATE NONCLUSTERED INDEX [IX_PostHistory_CreationDate_UserId]
    ON [dbo].[PostHistory] ([CreationDate], [UserId])
    INCLUDE ([Comment])
    WITH
    (
        DATA_COMPRESSION = PAGE,
        ONLINE = ON,
        SORT_IN_TEMPDB = ON
    );
END;
GO

7. Create the user-centered Votes covering index

USE [SQLStorm];
GO

IF NOT EXISTS
(
    SELECT 1
    FROM sys.indexes
    WHERE object_id = OBJECT_ID(N'dbo.Votes')
      AND name = N'IX_Votes_UserId_Cover'
)
BEGIN
    CREATE NONCLUSTERED INDEX [IX_Votes_UserId_Cover]
    ON [dbo].[Votes] ([UserId])
    INCLUDE ([VoteTypeId], [BountyAmount])
    WITH
    (
        DATA_COMPRESSION = PAGE,
        ONLINE = ON,
        SORT_IN_TEMPDB = ON
    );
END;
GO

8. Create the Comments PostId index

USE [SQLStorm];
GO

IF NOT EXISTS
(
    SELECT 1
    FROM sys.indexes
    WHERE object_id = OBJECT_ID(N'dbo.Comments')
      AND name = N'IX_Comments_PostId'
)
BEGIN
    CREATE NONCLUSTERED INDEX [IX_Comments_PostId]
    ON [dbo].[Comments] ([PostId])
    WITH
    (
        DATA_COMPRESSION = PAGE,
        ONLINE = ON,
        SORT_IN_TEMPDB = ON
    );
END;
GO

9. Create the optional filtered Badges Class 1 index

USE [SQLStorm];
GO

IF NOT EXISTS
(
    SELECT 1
    FROM sys.indexes
    WHERE object_id = OBJECT_ID(N'dbo.Badges')
      AND name = N'IX_Badges_Class1_UserId'
)
BEGIN
    CREATE NONCLUSTERED INDEX [IX_Badges_Class1_UserId]
    ON [dbo].[Badges] ([UserId])
    INCLUDE ([Id])
    WHERE [Class] = 1
    WITH
    (
        DATA_COMPRESSION = PAGE,
        ONLINE = ON,
        SORT_IN_TEMPDB = ON
    );
END;
GO

10. Re-trust foreign keys only when validation finds no violating rows

USE [SQLStorm];
GO

IF NOT EXISTS
(
    SELECT 1
    FROM [dbo].[Badges] AS c
    LEFT JOIN [dbo].[Users] AS p ON p.[Id] = c.[UserId]
    WHERE p.[Id] IS NULL
      AND c.[UserId] IS NOT NULL
)
BEGIN
    ALTER TABLE [dbo].[Badges] WITH CHECK CHECK CONSTRAINT [FK__Badges__UserId__6477ECF3];
END
ELSE
BEGIN
    PRINT N'Skipped FK__Badges__UserId__6477ECF3 because violating rows exist.';
END;
GO

IF NOT EXISTS
(
    SELECT 1
    FROM [dbo].[Comments] AS c
    LEFT JOIN [dbo].[Posts] AS p ON p.[Id] = c.[PostId]
    WHERE p.[Id] IS NULL
      AND c.[PostId] IS NOT NULL
)
BEGIN
    ALTER TABLE [dbo].[Comments] WITH CHECK CHECK CONSTRAINT [FK__Comments__PostId__4CA06362];
END
ELSE
BEGIN
    PRINT N'Skipped FK__Comments__PostId__4CA06362 because violating rows exist.';
END;
GO

IF NOT EXISTS
(
    SELECT 1
    FROM [dbo].[Comments] AS c
    LEFT JOIN [dbo].[Users] AS p ON p.[Id] = c.[UserId]
    WHERE p.[Id] IS NULL
      AND c.[UserId] IS NOT NULL
)
BEGIN
    ALTER TABLE [dbo].[Comments] WITH CHECK CHECK CONSTRAINT [FK__Comments__UserId__4D94879B];
END
ELSE
BEGIN
    PRINT N'Skipped FK__Comments__UserId__4D94879B because violating rows exist.';
END;
GO

IF NOT EXISTS
(
    SELECT 1
    FROM [dbo].[PostHistory] AS c
    LEFT JOIN [dbo].[PostHistoryTypes] AS p ON p.[Id] = c.[PostHistoryTypeId]
    WHERE p.[Id] IS NULL
      AND c.[PostHistoryTypeId] IS NOT NULL
)
BEGIN
    ALTER TABLE [dbo].[PostHistory] WITH CHECK CHECK CONSTRAINT [FK__PostHisto__PostH__5070F446];
END
ELSE
BEGIN
    PRINT N'Skipped FK__PostHisto__PostH__5070F446 because violating rows exist.';
END;
GO

IF NOT EXISTS
(
    SELECT 1
    FROM [dbo].[PostHistory] AS c
    LEFT JOIN [dbo].[Posts] AS p ON p.[Id] = c.[PostId]
    WHERE p.[Id] IS NULL
      AND c.[PostId] IS NOT NULL
)
BEGIN
    ALTER TABLE [dbo].[PostHistory] WITH CHECK CHECK CONSTRAINT [FK__PostHisto__PostI__5165187F];
END
ELSE
BEGIN
    PRINT N'Skipped FK__PostHisto__PostI__5165187F because violating rows exist.';
END;
GO

IF NOT EXISTS
(
    SELECT 1
    FROM [dbo].[PostHistory] AS c
    LEFT JOIN [dbo].[Users] AS p ON p.[Id] = c.[UserId]
    WHERE p.[Id] IS NULL
      AND c.[UserId] IS NOT NULL
)
BEGIN
    ALTER TABLE [dbo].[PostHistory] WITH CHECK CHECK CONSTRAINT [FK__PostHisto__UserI__52593CB8];
END
ELSE
BEGIN
    PRINT N'Skipped FK__PostHisto__UserI__52593CB8 because violating rows exist.';
END;
GO

IF NOT EXISTS
(
    SELECT 1
    FROM [dbo].[PostLinks] AS c
    LEFT JOIN [dbo].[LinkTypes] AS p ON p.[Id] = c.[LinkTypeId]
    WHERE p.[Id] IS NULL
      AND c.[LinkTypeId] IS NOT NULL
)
BEGIN
    ALTER TABLE [dbo].[PostLinks] WITH CHECK CHECK CONSTRAINT [FK__PostLinks__LinkT__571DF1D5];
END
ELSE
BEGIN
    PRINT N'Skipped FK__PostLinks__LinkT__571DF1D5 because violating rows exist.';
END;
GO

IF NOT EXISTS
(
    SELECT 1
    FROM [dbo].[PostLinks] AS c
    LEFT JOIN [dbo].[Posts] AS p ON p.[Id] = c.[PostId]
    WHERE p.[Id] IS NULL
      AND c.[PostId] IS NOT NULL
)
BEGIN
    ALTER TABLE [dbo].[PostLinks] WITH CHECK CHECK CONSTRAINT [FK__PostLinks__PostI__5535A963];
END
ELSE
BEGIN
    PRINT N'Skipped FK__PostLinks__PostI__5535A963 because violating rows exist.';
END;
GO

IF NOT EXISTS
(
    SELECT 1
    FROM [dbo].[PostLinks] AS c
    LEFT JOIN [dbo].[Posts] AS p ON p.[Id] = c.[RelatedPostId]
    WHERE p.[Id] IS NULL
      AND c.[RelatedPostId] IS NOT NULL
)
BEGIN
    ALTER TABLE [dbo].[PostLinks] WITH CHECK CHECK CONSTRAINT [FK__PostLinks__Relat__5629CD9C];
END
ELSE
BEGIN
    PRINT N'Skipped FK__PostLinks__Relat__5629CD9C because violating rows exist.';
END;
GO

IF NOT EXISTS
(
    SELECT 1
    FROM [dbo].[Posts] AS c
    LEFT JOIN [dbo].[Posts] AS p ON p.[Id] = c.[AcceptedAnswerId]
    WHERE p.[Id] IS NULL
      AND c.[AcceptedAnswerId] IS NOT NULL
)
BEGIN
    ALTER TABLE [dbo].[Posts] WITH CHECK CHECK CONSTRAINT [FK__Posts__AcceptedA__48CFD27E];
END
ELSE
BEGIN
    PRINT N'Skipped FK__Posts__AcceptedA__48CFD27E because violating rows exist.';
END;
GO

IF NOT EXISTS
(
    SELECT 1
    FROM [dbo].[Posts] AS c
    LEFT JOIN [dbo].[Users] AS p ON p.[Id] = c.[LastEditorUserId]
    WHERE p.[Id] IS NULL
      AND c.[LastEditorUserId] IS NOT NULL
)
BEGIN
    ALTER TABLE [dbo].[Posts] WITH CHECK CHECK CONSTRAINT [FK__Posts__LastEdito__47DBAE45];
END
ELSE
BEGIN
    PRINT N'Skipped FK__Posts__LastEdito__47DBAE45 because violating rows exist.';
END;
GO

IF NOT EXISTS
(
    SELECT 1
    FROM [dbo].[Posts] AS c
    LEFT JOIN [dbo].[Users] AS p ON p.[Id] = c.[OwnerUserId]
    WHERE p.[Id] IS NULL
      AND c.[OwnerUserId] IS NOT NULL
)
BEGIN
    ALTER TABLE [dbo].[Posts] WITH CHECK CHECK CONSTRAINT [FK__Posts__OwnerUser__46E78A0C];
END
ELSE
BEGIN
    PRINT N'Skipped FK__Posts__OwnerUser__46E78A0C because violating rows exist.';
END;
GO

IF NOT EXISTS
(
    SELECT 1
    FROM [dbo].[Posts] AS c
    LEFT JOIN [dbo].[Posts] AS p ON p.[Id] = c.[ParentId]
    WHERE p.[Id] IS NULL
      AND c.[ParentId] IS NOT NULL
)
BEGIN
    ALTER TABLE [dbo].[Posts] WITH CHECK CHECK CONSTRAINT [FK__Posts__ParentId__49C3F6B7];
END
ELSE
BEGIN
    PRINT N'Skipped FK__Posts__ParentId__49C3F6B7 because violating rows exist.';
END;
GO

IF NOT EXISTS
(
    SELECT 1
    FROM [dbo].[Posts] AS c
    LEFT JOIN [dbo].[PostTypes] AS p ON p.[Id] = c.[PostTypeId]
    WHERE p.[Id] IS NULL
      AND c.[PostTypeId] IS NOT NULL
)
BEGIN
    ALTER TABLE [dbo].[Posts] WITH CHECK CHECK CONSTRAINT [FK__Posts__PostTypeI__45F365D3];
END
ELSE
BEGIN
    PRINT N'Skipped FK__Posts__PostTypeI__45F365D3 because violating rows exist.';
END;
GO

IF NOT EXISTS
(
    SELECT 1
    FROM [dbo].[Tags] AS c
    LEFT JOIN [dbo].[Posts] AS p ON p.[Id] = c.[ExcerptPostId]
    WHERE p.[Id] IS NULL
      AND c.[ExcerptPostId] IS NOT NULL
)
BEGIN
    ALTER TABLE [dbo].[Tags] WITH CHECK CHECK CONSTRAINT [FK__Tags__ExcerptPos__59FA5E80];
END
ELSE
BEGIN
    PRINT N'Skipped FK__Tags__ExcerptPos__59FA5E80 because violating rows exist.';
END;
GO

IF NOT EXISTS
(
    SELECT 1
    FROM [dbo].[Tags] AS c
    LEFT JOIN [dbo].[Posts] AS p ON p.[Id] = c.[WikiPostId]
    WHERE p.[Id] IS NULL
      AND c.[WikiPostId] IS NOT NULL
)
BEGIN
    ALTER TABLE [dbo].[Tags] WITH CHECK CHECK CONSTRAINT [FK__Tags__WikiPostId__5AEE82B9];
END
ELSE
BEGIN
    PRINT N'Skipped FK__Tags__WikiPostId__5AEE82B9 because violating rows exist.';
END;
GO

IF NOT EXISTS
(
    SELECT 1
    FROM [dbo].[Votes] AS c
    LEFT JOIN [dbo].[Users] AS p ON p.[Id] = c.[UserId]
    WHERE p.[Id] IS NULL
      AND c.[UserId] IS NOT NULL
)
BEGIN
    ALTER TABLE [dbo].[Votes] WITH CHECK CHECK CONSTRAINT [FK__Votes__UserId__5EBF139D];
END
ELSE
BEGIN
    PRINT N'Skipped FK__Votes__UserId__5EBF139D because violating rows exist.';
END;
GO

IF NOT EXISTS
(
    SELECT 1
    FROM [dbo].[Votes] AS c
    LEFT JOIN [dbo].[VoteTypes] AS p ON p.[Id] = c.[VoteTypeId]
    WHERE p.[Id] IS NULL
      AND c.[VoteTypeId] IS NOT NULL
)
BEGIN
    ALTER TABLE [dbo].[Votes] WITH CHECK CHECK CONSTRAINT [FK__Votes__VoteTypeI__5DCAEF64];
END
ELSE
BEGIN
    PRINT N'Skipped FK__Votes__VoteTypeI__5DCAEF64 because violating rows exist.';
END;
GO