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
This article describes how to enable [data compression](data-compression.md) on an existing table or index in [!INCLUDE [ssnoversion](../../includes/ssnoversion-md.md)] by using [!INCLUDE [ssManStudioFull](../../includes/ssmanstudiofull-md.md)] or [!INCLUDE [tsql](../../includes/tsql-md.md)]. To enable data compression when creating a table or index, see the [Create a compressed index](../../t-sql/statements/create-index-transact-sql.md#l-create-a-compressed-index) and [Creating a table that uses row compression](../../t-sql/statements/create-table-transact-sql.md#n-creating-a-table-that-uses-row-compression) examples.
30
30
31
-
## Limitations and restrictions
31
+
## Limitations
32
32
33
33
- System tables can't be enabled for compression.
34
34
@@ -92,13 +92,16 @@ Requires `ALTER` permission on the table or index.
92
92
93
93
If you select **Create script**, the following options are available under **Script options**:
94
94
95
-
-**Script to file**
95
+
-**Script to file**
96
+
96
97
Generates the script as a `.sql` file. Enter a file name and location in the **File name** box or select **Browse** to open the **Script File Location** dialog box. From **Save As**, select **Unicode text** or **ANSI text**.
97
98
98
-
-**Script to Clipboard**
99
+
-**Script to Clipboard**
100
+
99
101
Saves the script to the Clipboard.
100
102
101
-
-**Script to New Query Window**
103
+
-**Script to New Query Window**
104
+
102
105
Generates the script to a new Query Editor window. This is the default selection.
103
106
104
107
- If you select **Schedule**, select **Change schedule**.
@@ -195,21 +198,21 @@ Requires `ALTER` permission on the table or index.
195
198
196
199
## <aid="TsqlProcedure"></a> Use Transact-SQL
197
200
198
-
### SQL Server and Azure SQL Database
201
+
In your database of choice, run [sp_estimate_data_compression_savings (Transact-SQL)](../system-stored-procedures/sp-estimate-data-compression-savings-transact-sql.md) and then enable compression on the table or index. See the following sections.
199
202
200
-
In [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] or [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)], run `sp_estimate_data_compression_savings` and then enable compression on the table or index. See the following sections.
1. In **Object Explorer**, connect to an instance of [!INCLUDE [ssDE](../../includes/ssde-md.md)].
205
208
206
209
1. On the Standard bar, select **New Query**.
207
210
211
+
1. Make sure you are in the context of your database.
212
+
208
213
1. Copy and paste the following example into the query window and select **Execute**. The example first executes the stored procedure `sp_estimate_data_compression_savings` to return the estimated size of the object if it were to use the `ROW` compression setting. The example then enables `ROW` compression on all partitions in the specified table.
ALTERTABLEProduction.TransactionHistory REBUILD PARTITION = ALL
@@ -223,11 +226,11 @@ In [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] or [!INCLUDE [ssaz
223
226
224
227
1. On the Standard bar, select **New Query**.
225
228
229
+
1. Make sure you are in the context of your database.
230
+
226
231
1. Copy and paste the following example into the query window and select **Execute**. The example first queries the `sys.indexes` catalog view to return the name and `index_id` for each index on the `Production.TransactionHistory` table. It then executes the stored procedure `sp_estimate_data_compression_savings` to return the estimated size of the specified index ID if it were to use the `PAGE` compression setting. Finally, the example rebuilds index ID 2 (`IX_TransactionHistory_ProductID`), specifying `PAGE` compression.
227
232
228
233
```sql
229
-
USE AdventureWorks2022;
230
-
GO
231
234
SELECT name, index_id
232
235
FROMsys.indexes
233
236
WHERE OBJECT_NAME (object_id) = N'TransactionHistory';
@@ -243,13 +246,13 @@ In [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] or [!INCLUDE [ssaz
243
246
GO
244
247
```
245
248
246
-
For more information, see [ALTER TABLE (Transact-SQL)](../../t-sql/statements/alter-table-transact-sql.md) and [ALTER INDEX (Transact-SQL)](../../t-sql/statements/alter-index-transact-sql.md).
249
+
For more information, see [ALTER TABLE](../../t-sql/statements/alter-table-transact-sql.md) and [ALTER INDEX](../../t-sql/statements/alter-index-transact-sql.md).
0 commit comments