Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

SQL Server Error 1092: Statistics Name Fix

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

SQL Server error 1092 occurs when the query optimizer tries to use or update a statistics object whose name is missing, invalid, or no longer exists. The message usually reads: “The statistics 'name' cannot be found” or “Statistics 'name' does not exist.” The fix is to identify the exact statistics object referenced in the error, check whether it still exists on the table or indexed view, and either recreate it with the correct name or drop and rebuild it. You need a login with ALTER permission on the affected table or database, and a way to run T-SQL (SSMS, Azure Data Studio, or sqlcmd).

What You'll Need

  • A SQL Server login with at least ALTER permission on the affected table, or db_owner on the database.
  • SQL Server Management Studio (SSMS), Azure Data Studio, or sqlcmd to run queries.
  • The full error text, including the statistics name and the object name (table or indexed view).
  • The database name where the error occurs.

Step-by-Step

  1. Capture the exact error text. Run the failing query or check the SQL Server error log and note the statistics name and the table or indexed view name. The error often appears as: “Statistics 'S' does not exist” or “The statistics 'S' cannot be found.” Write down both names exactly, including case and any schema prefix.
  2. Confirm the database context. In SSMS, select the correct database from the dropdown, or run USE YourDatabaseName; at the top of your query window. Statistics are scoped to a database, so checking the wrong database will make a valid object look missing.
  3. List the statistics on the affected table. Run:
    SELECT name, stats_id, auto_created, user_created FROM sys.stats WHERE object_id = OBJECT_ID('dbo.YourTable');
    Replace dbo.YourTable with the real schema and table name. If the statistics name from the error is not in the list, it has been dropped or renamed. If it is present, note the stats_id and continue.
  4. Check for a name mismatch. Compare the name in the error with the names in sys.stats. A trailing space, a different case, or a schema prefix can cause the lookup to fail. If the error names a statistics object that does not exist but a similar one does, the query or stored procedure may be referencing an old name.
  5. Recreate the missing statistics. If the object is genuinely missing, create it manually with the same name the query expects:
    CREATE STATISTICS S ON dbo.YourTable (YourColumn);
    Use the exact name from the error. If the statistics were auto-created and you do not know the column list, run sp_helpstats 'dbo.YourTable', 'ALL'; to see existing statistics and their columns, then create a replacement on the same columns.
  6. If the statistics exist but are corrupt or stale, drop and recreate. Run DROP STATISTICS dbo.YourTable.S; then recreate it with CREATE STATISTICS as above. Dropping statistics is safe for data, but it removes the optimizer’s distribution information until the new statistics are built. Avoid doing this during peak hours on large tables.
  7. Update the statistics instead of recreating when possible. If the object exists, run UPDATE STATISTICS dbo.YourTable S; to refresh it. This is often enough when the error is caused by stale metadata or a failed auto-update.
  8. Refresh the object metadata. If you renamed or recreated the table, run sp_refreshsqlmodule 'dbo.YourProcedure'; for any stored procedure, function, or view that references the statistics. Schema-bound modules can hold stale references after a rename.
  9. Test the original query again. Run the exact query or stored procedure that produced the error. If the error persists, move to the Troubleshooting section below.

Common Mistakes

  • Running the fix in the wrong database. Always confirm with SELECT DB_NAME(); before creating or dropping statistics.
  • Creating statistics with a different name than the one in the error. The optimizer looks up the exact name, so a near match will not resolve the error.
  • Dropping statistics on a large table during business hours. Rebuilding statistics can cause blocking and a temporary performance drop.
  • Assuming the statistics are missing when they are actually disabled or auto-created. Check the auto_created and user_created columns in sys.stats.
  • Ignoring schema changes. If a column was dropped or renamed, the statistics that referenced it may be invalid or gone; recreate statistics only on existing columns.

Tips

  • Use sp_autostats 'dbo.YourTable', 'ON'; to make sure automatic statistics creation is enabled for the table, so missing statistics are rebuilt automatically after data changes.
  • For large tables, consider UPDATE STATISTICS dbo.YourTable WITH FULLSCAN; to get accurate distribution data, but run it during a maintenance window.
  • Script out the existing statistics before dropping them: right-click the statistics in SSMS Object Explorer and choose Script Statistics as > CREATE To. This gives you a rollback script.
  • Keep statistics names consistent across environments. If a stored procedure references a statistics name explicitly, use the same name in development, test, and production.
  • Check for case-sensitive collation. In a case-sensitive database, StatsName and statsname are different objects.

Troubleshooting

If the error continues after recreating the statistics, work through these checks in order:

  1. Verify the object exists. Run SELECT OBJECT_NAME(object_id) FROM sys.stats WHERE name = 'S'; to see which table owns the statistics. If no row returns, the statistics do not exist in the current database.
  2. Check for a schema-bound reference. Schema-bound views and functions cannot be altered without dropping them. Use sp_refreshsqlmodule on dependent modules, or drop and recreate the schema-bound object if necessary. Dropping a schema-bound view loses its permissions and dependencies, so script it first.
  3. Look for a disabled statistics object. Run SELECT name, is_disabled FROM sys.stats WHERE object_id = OBJECT_ID('dbo.YourTable'); If is_disabled is 1, enable it with UPDATE STATISTICS dbo.YourTable S WITH RESAMPLE; or recreate it.
  4. Check for a failed auto-statistics update. Query sys.dm_db_stats_properties for the statistics to see last_updated and rows_sampled. If the statistics are very old, update them manually.
  5. Restart the SQL Server service only as a last resort. A restart clears cached plans that may reference the old statistics name. Save your work and warn other users first; a restart interrupts all connections.
  6. If the error occurs in a maintenance plan or job, check the job step. The step may reference a statistics name that was renamed. Edit the job step to use the current name.

Frequently Asked Questions

What does SQL Server error 1092 mean exactly?

It means the query optimizer or a statement tried to use a statistics object that could not be found by name. The statistics may have been dropped, renamed, or never created.

Can I ignore error 1092 if my query still runs?

No. The error usually means the optimizer is missing distribution data, which can lead to poor query plans and slow performance. Fix it by recreating or updating the statistics.

Does recreating statistics lock the table?

Creating or updating statistics can take a schema modification lock briefly, and a full scan can block writes on large tables. Schedule it during low activity.

How do I find which statistics a stored procedure references?

Search the procedure definition with sp_helptext 'dbo.YourProcedure'; and look for the statistics name. If the name is not explicit, the reference may come from a cached plan; clearing the plan cache or restarting SQL Server can help.

What if the statistics name contains special characters or spaces?

Use delimiters in your T-SQL: [Statistics Name] or "Statistics Name". The error text may show the name without delimiters, so match it exactly.

Is it safe to drop and recreate statistics on a production table?

It is safe for data integrity, but it temporarily removes optimizer information. Always script the existing statistics first and perform the change during a maintenance window.