|
| 1 | +--- |
| 2 | +title: Delete data |
| 3 | +description: This article describes delete scenarios, including purge, dropping extents and retention based deletes. |
| 4 | +ms.reviewer: avneraa |
| 5 | +ms.topic: how-to |
| 6 | +ms.date: 10/11/2024 |
| 7 | +--- |
| 8 | +# Delete data |
| 9 | + |
| 10 | +> [!INCLUDE [applies](../includes/applies-to-version/applies.md)] [!INCLUDE [fabric](../includes/applies-to-version/fabric.md)] [!INCLUDE [azure-data-explorer](../includes/applies-to-version/azure-data-explorer.md)] |
| 11 | +
|
| 12 | +Delete data from a table is supported in several ways. Use the following information to help you choose which deletion method is best for your use case. |
| 13 | + |
| 14 | +:::moniker range="azure-data-explorer" |
| 15 | +| Use case | Considerations | Method | |
| 16 | +|--|--|--| |
| 17 | +| Delete all data from a table. | | [Use the `.clear table data` command](#delete-all-data-in-a-table) | |
| 18 | +| Routinely delete old data. | Use if you need an automated deletion solution. | [Use a retention policy](#delete-data-using-a-retention-policy) | |
| 19 | +| Bulk delete specific data by extents. | Only use if you're an expert user. | [Use the `.drop extents` command](#delete-data-by-dropping-extents) | |
| 20 | +| Delete records based on their content. | - Storage artifacts that contain the deleted records aren't necessarily deleted. <br /> - Deleted records can't be recovered (regardless of any retention or recoverability settings). <br />- Use if you need a quick way to delete records. | [Use soft delete](#soft-delete)| |
| 21 | +| Delete records based on their content. | - Storage artifacts that contain the deleted records are deleted. <br /> - Deleted records can't be recovered (regardless of any retention or recoverability settings). <br />- Requires significant system resources and time to complete. | [Use purge](#purge) | |
| 22 | +:::moniker-end |
| 23 | + |
| 24 | +:::moniker range="microsoft-fabric" |
| 25 | +| Use case | Considerations | Method | |
| 26 | +|--|--|--| |
| 27 | +| Delete all data from a table. | | [Use the `.clear table data` command](#delete-all-data-in-a-table) | |
| 28 | +| Routinely delete old data. | Use if you need an automated deletion solution. | [Use a retention policy](#delete-data-using-a-retention-policy) | |
| 29 | +| Bulk delete specific data by extents. | Only use if you're an expert user. | [Use the `.drop extents` command](#delete-data-by-dropping-extents) | |
| 30 | +| Delete records based on their content. | - Storage artifacts that contain the deleted records aren't necessarily deleted.<br /> - Deleted records can't be recovered (regardless of any retention or recoverability settings).<br />- Use if you need a quick way to delete records. | [Use soft delete](#delete-individual-rows) | |
| 31 | +:::moniker-end |
| 32 | + |
| 33 | +The following sections describe the different deletion methods. |
| 34 | + |
| 35 | +## Delete all data in a table |
| 36 | + |
| 37 | +To delete all data in a table, use the [.clear table data](../management/clear-table-data-command.md) command. This command is the most efficient way to remove all data from a table. |
| 38 | + |
| 39 | +Syntax: |
| 40 | + |
| 41 | +```kusto |
| 42 | +.clear table <TableName> data |
| 43 | +``` |
| 44 | + |
| 45 | +## Delete data using a retention policy |
| 46 | + |
| 47 | +Automatically delete data based on a [retention policy](../management/retention-policy.md). You can set the retention policy at the database or table level. There's no guarantee as to when the deletion occurs, but it will not be deleted before the retention period. This is an efficient and convenient way to remove old data. |
| 48 | + |
| 49 | +Consider a database or table that is set for 90 days of retention. If only 60 days of data are needed, delete the older data as follows: |
| 50 | + |
| 51 | +```kusto |
| 52 | +.alter-merge database <DatabaseName> policy retention softdelete = 60d |
| 53 | +
|
| 54 | +.alter-merge table <TableName> policy retention softdelete = 60d |
| 55 | +``` |
| 56 | + |
| 57 | +## Delete data by dropping extents |
| 58 | + |
| 59 | +[Extent (data shard)](../management/extents-overview.md) is the internal structure where data is stored. Each extent can hold up to millions of records. Extents can be deleted individually or as a group using [drop extent(s) commands](../management/drop-extents.md). |
| 60 | + |
| 61 | +### Examples |
| 62 | + |
| 63 | +You can delete all rows in a table or just a specific extent. |
| 64 | + |
| 65 | +- Delete all rows in a table: |
| 66 | + |
| 67 | + ```kusto |
| 68 | + .drop extents from TestTable |
| 69 | + ``` |
| 70 | +
|
| 71 | +- Delete a specific extent: |
| 72 | +
|
| 73 | + ```kusto |
| 74 | + .drop extent e9fac0d2-b6d5-4ce3-bdb4-dea052d13b42 |
| 75 | + ``` |
| 76 | +
|
| 77 | +## Delete individual rows |
| 78 | +
|
| 79 | +:::moniker range="azure-data-explorer" |
| 80 | +Both purge and soft delete can be used for deleting individual rows. Soft delete doesn't necessarily delete the storage artifacts that contain records to delete, and purge does delete all such storage artifacts. |
| 81 | +
|
| 82 | +Both methods prevent deleted records from being recovered, regardless of any retention or recoverability settings. The deletion process is final and irreversible. |
| 83 | +
|
| 84 | +### Soft delete |
| 85 | +
|
| 86 | +With [soft delete](data-soft-delete.md), data isn't necessarily deleted from storage artifacts. This method marks all matching records as deleted, so that they'll be filtered out in queries, and doesn't require significant system resources. |
| 87 | +
|
| 88 | +### Purge |
| 89 | +
|
| 90 | +With [purge](data-purge.md), extents that have one or more records to be deleted, are replaced with new extents in which those records don't exist. This deletion process isn't immediate, requires significant system resources, and can take a whole day to complete. |
| 91 | +::: moniker-end |
| 92 | +
|
| 93 | +:::moniker range="microsoft-fabric" |
| 94 | +[Soft delete](data-soft-delete.md) can be used for deleting individual rows. Data isn't necessarily deleted from storage artifacts. Soft delete prevent deleted records from being recovered, regardless of any retention or recoverability settings. The deletion process is final and irreversible. This method marks all matching records as deleted, so that they'll be filtered out in queries, and doesn't require significant system resources. |
| 95 | +::: moniker-end |
0 commit comments