You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit a2c973f
Browse filesBrowse the repository at this point in the historyBrowse files
*Applies to**: [!INCLUDE[ssSDSfull](../../includes/sssdsfull-md.md)], [!INCLUDE[ssazuremi_md](../../includes/ssazuremi_md.md)], and starting with [!INCLUDE[ssSQL22](../../includes/sssql22-md.md)]
192
192
193
-
Prior to [!INCLUDE[sssql22-md](../../includes/sssql22-md.md)], if statistics are manually created by a user or third party tool on a user database, those statistics objects can block or interfere with schema changes the customer may desire.
193
+
In [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] prior to [!INCLUDE[sssql22-md](../../includes/sssql22-md.md)], if statistics are manually created by a user or third party tool on a user database, those statistics objects can block or interfere with schema changes the customer may desire.
194
194
195
-
Starting with [!INCLUDE[sssql22-md](../../includes/sssql22-md.md)], the AUTO_DROP option is enabled by default on all new and migrated databases. The AUTO_DROP property allows the creation of statistics objects in a mode such that a subsequent schema change will *not* be blocked by the statistic object, but instead the statistics will be dropped as necessary. In this way, manually-created statistics with AUTO_DROP enabled behave like auto-created statistics.
195
+
Starting with [!INCLUDE[sssql22-md](../../includes/sssql22-md.md)], the auto drop option is enabled by default on all new and migrated databases. The AUTO_DROP property allows the creation of statistics objects in a mode such that a subsequent schema change will *not* be blocked by the statistic object, but instead the statistics will be dropped as necessary. In this way, manually-created statistics with auto drop enabled behave like auto-created statistics.
196
196
197
197
> [!NOTE]
198
-
> Trying to set or unset the *Auto_Drop*property on auto-created statistics may raise errors. Auto-created statistics always uses auto drop. Some backups, when restored, may have this property set incorrectly until the next time the statistics object is updated (manually or automatically). However, auto-created statistics always behave like auto drop statistics. When restoring a database to [!INCLUDE[sssql22-md](../../includes/sssql22-md.md)] from a previous version, it is recommended to execute `sp_updatestats` on the database, setting the proper metadata for the statistics AUTO_DROP feature.
198
+
> Trying to set or unset the auto drop property on auto-created statistics may raise errors. Auto-created statistics always uses auto drop. Some backups, when restored, may have this property set incorrectly until the next time the statistics object is updated (manually or automatically). However, auto-created statistics always behave like auto drop statistics. When restoring a database to [!INCLUDE[sssql22-md](../../includes/sssql22-md.md)] from a previous version, it is recommended to execute `sp_updatestats` on the database, setting the proper metadata for the statistics auto drop feature.
199
199
200
200
For example, to manually create a statistics object on the `dbo.DatabaseLog` table:
201
201
202
202
```sql
203
203
CREATE STATISTICS [mystats] ON [dbo].[DatabaseLog]([DatabaseLogID], [PostTime], [DatabaseUser]) WITH AUTO_DROP =ON;
204
204
```
205
205
206
-
For example, to update a statistics object AUTO_DROP setting on the `dbo.DatabaseLog` table:
206
+
For example, to update a statistics object auto drop setting on the `dbo.DatabaseLog` table:
207
207
208
208
```sql
209
209
UPDATE STATISTICS [dbo].[DatabaseLog] [mystats] WITH AUTO_DROP =ON;
210
210
```
211
211
212
+
To evaluate the auto drop setting on existing statistics, use the `auto_drop` column in `sys.stats`:
213
+
214
+
```sql
215
+
SELECT object_id, [name], auto_drop
216
+
FROMsys.stats;
217
+
```
218
+
212
219
For more information, see [CREATE STATISTICS (Transact-SQL)](../../t-sql/statements/create-statistics-transact-sql.md#auto_drop---on--off-)
Contains a row for each statistics object that exists for the tables, indexes, and indexed views in the database in [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)]. Every index will have a corresponding statistics row with the same name and ID (**index_id** = **stats_id**), but not every statistics row has a corresponding index.
27
-
28
-
The catalog view [sys.stats_columns](../../relational-databases/system-catalog-views/sys-stats-columns-transact-sql.md) provides statistics information for each column in the database. For more information about statistics, see [Statistics](../../relational-databases/statistics/statistics.md).
|**object_id**|**int**|ID of the object to which these statistics belong.|
33
-
|**name**|**sysname**|Name of the statistics. Is unique within the object.|
34
-
|**stats_id**|**int**|ID of the statistics. Is unique within the object.<br /><br />If statistics correspond to an index, the *stats_id* value is the same as the *index_id* value in the [sys.indexes](../../relational-databases/system-catalog-views/sys-indexes-transact-sql.md) catalog view.|
35
-
|**auto_created**|**bit**|Indicates whether the statistics were automatically created by [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)].<br /><br /> 0 = Statistics were not automatically created by [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)].<br /><br /> 1 = Statistics were automatically created by [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)].|
36
-
|**user_created**|**bit**|Indicates whether the statistics were created by a user.<br /><br /> 0 = Statistics were not created by a user.<br /><br /> 1 = Statistics were created by a user.|
37
-
|**no_recompute**|**bit**|Indicates whether the statistics were created with the **NORECOMPUTE** option.<br /><br /> 0 = Statistics were not created with the **NORECOMPUTE** option.<br /><br /> 1 = Statistics were created with the **NORECOMPUTE** option.|
38
-
|**has_filter**|**bit**|0 = Statistics do not have a filter and are computed on all rows.<br /><br /> 1 = Statistics have a filter and are computed only on rows that satisfy the filter definition.|
39
-
|**filter_definition**|**nvarchar(max)**|Expression for the subset of rows included in filtered statistics.<br /><br /> NULL = Non-filtered statistics.|
40
-
|**is_temporary**|**bit**|Indicates whether the statistics is temporary. Temporary statistics support [!INCLUDE[ssHADR](../../includes/sshadr-md.md)] secondary databases that are enabled for read-only access.<br /><br /> 0 = The statistics is not temporary.<br /><br /> 1 = The statistics is temporary.<br /><br />**Applies to**: [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] (Starting with [!INCLUDE[ssSQL11](../../includes/sssql11-md.md)])|
41
-
|**is_incremental**|**bit**|Indicate whether the statistics are created as incremental statistics.<br /><br /> 0 = The statistics are not incremental.<br /><br /> 1 = The statistics are incremental.<br /><br />**Applies to**: [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] (Starting with [!INCLUDE[ssSQL14](../../includes/sssql14-md.md)])|
42
-
|**has_persisted_sample**|**bit**|Indicates whether the statistics were created or updated with the PERSIST_SAMPLE_PERCENT option.<br /><br /> **0** = Statistics are not persisting the sample percentage.<br /><br /> 1 = Statistics were created or updated with the PERSIST_SAMPLE_PERCENT option.<br /><br />**Applies to**: [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] (Starting with [!INCLUDE[sssql19-md](../../includes/sssql19-md.md)])|
43
-
|**stats_generation_method**|**int**|Indicates the method by which statistics are created.<br /><br />**0** = Sort based statistics<br /><br />1 = Internal use only<br /><br />**Applies to**: [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] (Starting with [!INCLUDE[sssql19-md](../../includes/sssql19-md.md)])|
44
-
|**stats_generation_method_desc**|**varchar(255)**|The text description of the method by which statistics are created.<br /><br />Sort based statistics<br /><br />Internal use only<br /><br />**Applies to**: [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] (Starting with [!INCLUDE[sssql19-md](../../includes/sssql19-md.md)])|
45
-
46
-
## Permissions
47
-
[!INCLUDE[ssCatViewPerm](../../includes/sscatviewperm-md.md)] For more information, see [Metadata Visibility Configuration](../../relational-databases/security/metadata-visibility-configuration.md).
48
-
49
-
## Examples
50
-
The following examples returns all the statistics and statistics columns for the `HumanResources.Employee` table.
Contains a row for each statistics object that exists for the tables, indexes, and indexed views in the database in [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)]. Every index will have a corresponding statistics row with the same name and ID (`index_id` = `stats_id`), but not every statistics row has a corresponding index.
26
+
27
+
The catalog view [sys.stats_columns](../../relational-databases/system-catalog-views/sys-stats-columns-transact-sql.md) provides statistics information for each column in the database. For more information about statistics, see [Statistics](../../relational-databases/statistics/statistics.md).
|**object_id**|**int**|ID of the object to which these statistics belong.|
32
+
|**name**|**sysname**|Name of the statistics. Is unique within the object.|
33
+
|**stats_id**|**int**|ID of the statistics. Is unique within the object.<br /><br />If statistics correspond to an index, the *stats_id* value is the same as the *index_id* value in the [sys.indexes](../../relational-databases/system-catalog-views/sys-indexes-transact-sql.md) catalog view.|
34
+
|**auto_created**|**bit**|Indicates whether the statistics were automatically created by [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)].<br /><br />0 = Statistics were not automatically created by [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)].<br /><br />1 = Statistics were automatically created by [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)].|
35
+
|**user_created**|**bit**|Indicates whether the statistics were created by a user.<br /><br />0 = Statistics were not created by a user.<br /><br />1 = Statistics were created by a user.|
36
+
|**no_recompute**|**bit**|Indicates whether the statistics were created with the **NORECOMPUTE** option.<br /><br />0 = Statistics were not created with the **NORECOMPUTE** option.<br /><br />1 = Statistics were created with the **NORECOMPUTE** option.|
37
+
|**has_filter**|**bit**|0 = Statistics do not have a filter and are computed on all rows.<br /><br />1 = Statistics have a filter and are computed only on rows that satisfy the filter definition.|
38
+
|**filter_definition**|**nvarchar(max)**|Expression for the subset of rows included in filtered statistics.<br /><br />NULL = Non-filtered statistics.|
39
+
|**is_temporary**|**bit**|Indicates whether the statistics is temporary. Temporary statistics support [!INCLUDE[ssHADR](../../includes/sshadr-md.md)] secondary databases that are enabled for read-only access.<br /><br />0 = The statistics is not temporary.<br /><br />1 = The statistics is temporary.<br /><br />**Applies to**: [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] (Starting with [!INCLUDE[ssSQL11](../../includes/sssql11-md.md)])|
40
+
|**is_incremental**|**bit**|Indicate whether the statistics are created as incremental statistics.<br /><br />0 = The statistics are not incremental.<br /><br />1 = The statistics are incremental.<br /><br />**Applies to**: [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] (Starting with [!INCLUDE[ssSQL14](../../includes/sssql14-md.md)])|
41
+
|**has_persisted_sample**|**bit**|Indicates whether the statistics were created or updated with the PERSIST_SAMPLE_PERCENT option.<br /><br />**0** = Statistics are not persisting the sample percentage.<br /><br />1 = Statistics were created or updated with the PERSIST_SAMPLE_PERCENT option.<br /><br />**Applies to**: [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] (Starting with [!INCLUDE[sssql19-md](../../includes/sssql19-md.md)])|
42
+
|**stats_generation_method**|**int**|Indicates the method by which statistics are created.<br /><br />**0** = Sort based statistics<br /><br />1 = Internal use only<br /><br />**Applies to**: [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] (Starting with [!INCLUDE[sssql19-md](../../includes/sssql19-md.md)])|
43
+
|**stats_generation_method_desc**|**varchar(255)**|The text description of the method by which statistics are created.<br /><br />Sort based statistics<br /><br />Internal use only<br /><br />**Applies to**: [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] (Starting with [!INCLUDE[sssql19-md](../../includes/sssql19-md.md)])|
44
+
|**auto_drop**|**bit**|Indicates whether or not the auto drop feature is enabled for this statistics object. The AUTO_DROP property allows the creation of statistics objects in a mode such that a subsequent schema change will not be blocked by the statistic object, but instead the statistics will be dropped as necessary. In this way, manually-created statistics with AUTO_DROP enabled behave like auto-created statistics. For more information, see [AUTO_DROP option](../statistics/statistics.md#auto_drop-option).<br /><br />**Applies to**: [!INCLUDE[ssSDSfull](../../includes/sssdsfull-md.md)], [!INCLUDE[ssazuremi_md](../../includes/ssazuremi_md.md)], and starting with [!INCLUDE[ssSQL22](../../includes/sssql22-md.md)]. |
45
+
46
+
## Permissions
47
+
48
+
[!INCLUDE[ssCatViewPerm](../../includes/sscatviewperm-md.md)] For more information, see [Metadata Visibility Configuration](../../relational-databases/security/metadata-visibility-configuration.md).
49
+
50
+
## Examples
51
+
52
+
The following examples returns all the statistics and statistics columns for the `HumanResources.Employee` table.
Copy file name to clipboardExpand all lines: docs/relational-databases/system-stored-procedures/sp-updatestats-transact-sql.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,7 +55,7 @@ For disk-based tables, `sp_updatestats` updates statistics based on the **modifi
55
55
56
56
For databases with a compatibility level below 90, executing `sp_updatestats` does not preserve the latest NORECOMPUTE setting for specific statistics. For databases with a compatibility level of 90 or higher, `sp_updatestats` does preserve the latest NORECOMPUTE option for specific statistics. For more information about disabling and re-enabling statistics updates, see [Statistics](../../relational-databases/statistics/statistics.md).
57
57
58
-
When restoring a database to [!INCLUDE[sssql22-md](../../includes/sssql22-md.md)] from a previous version, it is recommended to execute `sp_updatestats` on the database. This is related to setting proper metadata for the [statistics AUTO_DROP feature](../statistics/statistics.md#auto_drop-option) introduced in [!INCLUDE[sssql22-md](../../includes/sssql22-md.md)].
58
+
When restoring a database to [!INCLUDE[sssql22-md](../../includes/sssql22-md.md)] from a previous version, it is recommended to execute `sp_updatestats` on the database. This is related to setting proper metadata for the [statistics auto drop feature](../statistics/statistics.md#auto_drop-option) introduced in [!INCLUDE[sssql22-md](../../includes/sssql22-md.md)]. The auto drop feature is available in [!INCLUDE[ssSDSfull](../../includes/sssdsfull-md.md)], [!INCLUDE[ssazuremi_md](../../includes/ssazuremi_md.md)], and starting with [!INCLUDE[ssSQL22](../../includes/sssql22-md.md)].
0 commit comments