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
[!INCLUDE [SQL Server Azure SQL Database](../../includes/applies-to-version/sql-asdb.md)]
25
25
This article describes how to shrink a database in [!INCLUDE[ssnoversion](../../includes/ssnoversion-md.md)] by using Object Explorer in [!INCLUDE[ssManStudioFull](../../includes/ssmanstudiofull-md.md)] or [!INCLUDE[tsql](../../includes/tsql-md.md)].
- Consider the following information when you plan to shrink a database:
40
40
41
-
- A shrink operation is most effective after an operation that creates lots of unused space, such as a truncate table or a drop table operation.
41
+
- A shrink operation is most effective after an operation that creates a large amount of unused storage space, such as a large DELETE statement, truncate table, or a drop table operation.
42
42
43
-
- Most databases require some free space to be available for regular day-to-day operations. If you shrink a database repeatedly and notice that the database size grows again, this indicates that the space that was shrunk is required for regular operations. In these cases, repeatedly shrinking the database is a wasted operation, and likely created the need for autogrowth events to reclaim the space, hindering performance.
43
+
- Most databases require some free space to be available for regular day-to-day operations. If you shrink a database repeatedly and notice that the database size grows again, this indicates that the free space is required for regular operations. In these cases, repeatedly shrinking the database is a wasted operation. Autogrow events necessary to grow the database file(s) a hinder performance.
44
44
45
45
- A shrink operation does not preserve the fragmentation state of indexes in the database, and generally increases fragmentation to a degree. This is another reason not to repeatedly shrink the database.
46
46
47
47
- Unless you have a specific requirement, do not set the AUTO_SHRINK database option to ON.
Requires membership in the **sysadmin** fixed server role or the **db_owner** fixed database role.
51
-
51
+
52
+
## Remarks
53
+
54
+
Shrink operations in progress can block other queries on the database, and can be blocked by queries already in progress. Introduced in [!INCLUDE[sssql22-md](../../includes/sssql22-md.md)], shrink database operations have a WAIT_AT_LOW_PRIORITY option. This feature is a new additional option for `DBCC SHRINKDATABASE` and `DBCC SHRINKFILE`. This feature is a new additional option for `DBCC SHRINKDATABASE` and `DBCC SHRINKFILE`. If a new shrink operation in WAIT_AT_LOW_PRIORITY mode cannot obtain the necessary locks due to a long-running query already in progress, the shrink operation will eventually time out after one minute and quietly exit, preventing other queries from being blocked. For more information, see [DBCC SHRINKDATABASE](../../t-sql/database-console-commands/dbcc-shrinkdatabase-transact-sql.md).
55
+
52
56
## <aname="SSMSProcedure"></a> Use SQL Server Management Studio
Data that is moved to shrink a file can be scattered to any available location in the file. This causes index fragmentation and can slow the performance of queries that search a range of the index. To eliminate the fragmentation, consider rebuilding the indexes on the file after shrinking. For more information, see [Rebuild an index](../../relational-databases/indexes/reorganize-and-rebuild-indexes.md#rebuild-an-index).
94
98
95
-
## Next steps
96
-
-[Shrink a File](../../relational-databases/databases/shrink-a-file.md)
99
+
## See also
100
+
101
+
-[Considerations for the autogrow and autoshrink settings in SQL Server](/troubleshoot/sql/admin/considerations-autogrow-autoshrink)
102
+
-[Database Files and Filegroups](../../relational-databases/databases/database-files-and-filegroups.md)
This topic describes how to shrink a data or log file in [!INCLUDE[ssnoversion](../../includes/ssnoversion-md.md)] by using [!INCLUDE[ssManStudioFull](../../includes/ssmanstudiofull-md.md)] or [!INCLUDE[tsql](../../includes/tsql-md.md)].
26
+
27
+
This article describes how to shrink a data or log file in [!INCLUDE[ssnoversion](../../includes/ssnoversion-md.md)] by using [!INCLUDE[ssManStudioFull](../../includes/ssmanstudiofull-md.md)] or [!INCLUDE[tsql](../../includes/tsql-md.md)].
27
28
28
29
Shrinking data files recovers space by moving pages of data from the end of the file to unoccupied space closer to the front of the file. When enough free space is created at the end of the file, data pages at end of the file can be deallocated and returned to the file system.
29
30
30
-
**In This Topic**
31
-
32
-
-**Before you begin:**
33
-
34
-
[Limitations and Restrictions](#Restrictions)
35
-
36
-
[Recommendations](#Recommendations)
37
-
38
-
[Security](#Security)
39
-
40
-
-**To shrink a data or log file, using:**
41
-
42
-
[SQL Server Management Studio](#SSMSProcedure)
43
-
44
-
[Transact-SQL](#TsqlProcedure)
45
-
46
-
## <aname="BeforeYouBegin"></a> Before You Begin
47
-
48
31
### <aname="Restrictions"></a> Limitations and Restrictions
49
32
50
33
- The primary data file cannot be made smaller than the size of the primary file in the model database.
51
34
52
35
### <aname="Recommendations"></a> Recommendations
36
+
37
+
- A shrink operation is most effective after an operation that creates a large amount of unused storage space, such as a large DELETE statement, truncate table, or a drop table operation.
38
+
39
+
- Most databases require some free space to be available for regular day-to-day operations. If you shrink a database file repeatedly and notice that the database size grows again, this indicates that the free space is required for regular operations. In these cases, repeatedly shrinking the database file is a wasted operation. Autogrow events necessary to grow the database file a hinder performance.
53
40
54
41
- Data that is moved to shrink a file can be scattered to any available location in the file. This causes index fragmentation and can slow the performance of queries that search a range of the index. To eliminate the fragmentation, consider rebuilding the indexes on the file after shrinking.
55
-
56
-
### <aname="Security"></a> Security
57
-
58
-
#### <aname="Permissions"></a> Permissions
42
+
43
+
- Unless you have a specific requirement, do not set the AUTO_SHRINK database option to ON.
44
+
45
+
## Remarks
46
+
47
+
Shrink operations in progress can block other queries on the database, and can be blocked by queries already in progress. Introduced in [!INCLUDE[sssql22-md](../../includes/sssql22-md.md)], shrink file operations have a WAIT_AT_LOW_PRIORITY option. This feature is a new additional option for `DBCC SHRINKDATABASE` and `DBCC SHRINKFILE`. If a new shrink operation in WAIT_AT_LOW_PRIORITY mode cannot obtain the necessary locks due to a long-running query already in progress, the shrink operation will eventually time out after one minute and quietly exit, preventing other queries from being blocked. For more information, see [DBCC SHRINKFILE](../../t-sql/database-console-commands/dbcc-shrinkfile-transact-sql.md).
Requires membership in the **sysadmin** fixed server role or the **db_owner** fixed database role.
60
51
61
52
## <aname="SSMSProcedure"></a> Using SQL Server Management Studio
@@ -66,7 +57,7 @@ ms.author: wiassaf
66
57
67
58
2. Expand **Databases** and then right-click the database that you want to shrink.
68
59
69
-
3. Point to **Tasks**, point to **Shrink**, and then click**Files**.
60
+
3. Point to **Tasks**, point to **Shrink**, and then select**Files**.
70
61
71
62
**Database**
72
63
Displays the name of the selected database.
@@ -117,25 +108,31 @@ ms.author: wiassaf
117
108
118
109
Selecting this option moves all data from the specified file to other files in the filegroup. The empty file can then be deleted. This option is the same as executing DBCC SHRINKFILE with the EMPTYFILE option.
119
110
120
-
9.Click**OK**.
111
+
9.Select**OK**.
121
112
122
113
## <aname="TsqlProcedure"></a> Using Transact-SQL
123
114
124
115
#### To shrink a data or log file
125
116
126
117
1. Connect to the [!INCLUDE[ssDE](../../includes/ssde-md.md)].
127
118
128
-
2. From the Standard bar, click**New Query**.
119
+
2. From the Standard bar, select**New Query**.
129
120
130
-
3. Copy and paste the following example into the query window and click**Execute**. This example uses [DBCC SHRINKFILE](../../t-sql/database-console-commands/dbcc-shrinkfile-transact-sql.md) to shrink the size of a data file named `DataFile1` in the `UserDB` database to 7 MB.
121
+
3. Copy and paste the following example into the query window and select**Execute**. This example uses [DBCC SHRINKFILE](../../t-sql/database-console-commands/dbcc-shrinkfile-transact-sql.md) to shrink the size of a data file named `DataFile1` in the `UserDB` database to 7 MB.
0 commit comments