From 6c06527fd430ee2b2db6355062f6580d9365fa0e Mon Sep 17 00:00:00 2001 From: PragatiVerma18 Date: Mon, 9 Dec 2024 11:26:44 +0530 Subject: [PATCH 1/3] Add SQL truncate concept entry --- content/sql/concepts/truncate/truncate.md | 56 +++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 content/sql/concepts/truncate/truncate.md diff --git a/content/sql/concepts/truncate/truncate.md b/content/sql/concepts/truncate/truncate.md new file mode 100644 index 00000000000..6e1df6013be --- /dev/null +++ b/content/sql/concepts/truncate/truncate.md @@ -0,0 +1,56 @@ +--- +Title: 'TRUNCATE' +Description: 'The SQL TRUNCATE statement is used to quickly delete all rows from a table while retaining the table structure.' +Subjects: + - 'Data Science' + - 'Data Visualization' +Tags: + - 'Data' + - 'Database' + - 'Functions' + - 'SQL' +CatalogContent: + - 'learn-sql' + - 'paths/analyze-data-with-sql' +--- + +**`TRUNCATE`** is a SQL statement used to quickly delete all rows from a table while retaining the table structure. + +Unlike the `DELETE` statement, `TRUNCATE` does not log individual row deletions and does not generate triggers, making it faster for large datasets. + +## Key Characteristics + +- **Performance**: `TRUNCATE` is more efficient than `DELETE` because it uses minimal logging. +- **Data Integrity**: It resets identity columns (e.g., `AUTO_INCREMENT`) to their seed values. +- **Irreversibility**: `TRUNCATE` operations cannot be rolled back in most database systems, as it does not log row-level changes. +- **Constraints**: Cannot truncate a table that is referenced by a foreign key. + +## Comparison: TRUNCATE vs. DELETE + +| Feature | `TRUNCATE` | `DELETE` | +| ------------------------- | ----------------------------- | ------------------------- | +| **Row Logging** | No | Yes | +| **Triggers** | Not activated | Activated | +| **Rollback** | Not supported in many systems | Supported | +| **Identity Column Reset** | Yes | No | +| **Performance** | Faster | Slower for large datasets | + +## Syntax + +```pseudo +TRUNCATE TABLE table_name; +``` + +- `table_name`: Specifies the name of the table to truncate. + +> **Note**: Use `TRUNCATE` carefully in production environments, as it cannot be undone. + +## Example + +The `TRUNCATE` statement can be used to clear all records from a table while retaining its structure. For instance, to remove all data from a table named `employee_data`: + +```sql +TRUNCATE TABLE employee_data; +``` + +This removes all rows from the `employee_data` table without affecting the table's schema or structure. From 7bf150ef8323fa4c1f568269b966885c605715ad Mon Sep 17 00:00:00 2001 From: PragatiVerma18 Date: Mon, 9 Dec 2024 12:31:49 +0530 Subject: [PATCH 2/3] Fix file URL --- content/sql/concepts/{ => commands/terms}/truncate/truncate.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename content/sql/concepts/{ => commands/terms}/truncate/truncate.md (100%) diff --git a/content/sql/concepts/truncate/truncate.md b/content/sql/concepts/commands/terms/truncate/truncate.md similarity index 100% rename from content/sql/concepts/truncate/truncate.md rename to content/sql/concepts/commands/terms/truncate/truncate.md From 7df086c9fdd34e0108b15c0d503dd88f5d2bfc8d Mon Sep 17 00:00:00 2001 From: Sriparno Roy Date: Thu, 26 Dec 2024 21:04:40 +0530 Subject: [PATCH 3/3] Minor changes --- .../commands/terms/truncate/truncate.md | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/content/sql/concepts/commands/terms/truncate/truncate.md b/content/sql/concepts/commands/terms/truncate/truncate.md index 6e1df6013be..7e77973d32c 100644 --- a/content/sql/concepts/commands/terms/truncate/truncate.md +++ b/content/sql/concepts/commands/terms/truncate/truncate.md @@ -1,6 +1,6 @@ --- Title: 'TRUNCATE' -Description: 'The SQL TRUNCATE statement is used to quickly delete all rows from a table while retaining the table structure.' +Description: 'Deletes all rows from a table while retaining the table structure.' Subjects: - 'Data Science' - 'Data Visualization' @@ -14,26 +14,24 @@ CatalogContent: - 'paths/analyze-data-with-sql' --- -**`TRUNCATE`** is a SQL statement used to quickly delete all rows from a table while retaining the table structure. - -Unlike the `DELETE` statement, `TRUNCATE` does not log individual row deletions and does not generate triggers, making it faster for large datasets. +**`TRUNCATE`** is a SQL statement used to quickly delete all rows from a table while retaining the table structure. Unlike the **`DELETE`** statement, `TRUNCATE` does not log individual row deletions and does not generate triggers, making it faster for large datasets. ## Key Characteristics -- **Performance**: `TRUNCATE` is more efficient than `DELETE` because it uses minimal logging. -- **Data Integrity**: It resets identity columns (e.g., `AUTO_INCREMENT`) to their seed values. -- **Irreversibility**: `TRUNCATE` operations cannot be rolled back in most database systems, as it does not log row-level changes. -- **Constraints**: Cannot truncate a table that is referenced by a foreign key. +- _Performance_: `TRUNCATE` is more efficient than `DELETE` because it uses minimal logging. +- _Data Integrity_: It resets identity columns (e.g., `AUTO_INCREMENT`) to their seed values. +- _Irreversibility_: `TRUNCATE` operations cannot be rolled back in most database systems, as it does not log row-level changes. +- _Constraints_: Cannot truncate a table that is referenced by a foreign key. ## Comparison: TRUNCATE vs. DELETE -| Feature | `TRUNCATE` | `DELETE` | -| ------------------------- | ----------------------------- | ------------------------- | -| **Row Logging** | No | Yes | -| **Triggers** | Not activated | Activated | -| **Rollback** | Not supported in many systems | Supported | -| **Identity Column Reset** | Yes | No | -| **Performance** | Faster | Slower for large datasets | +| Feature | `TRUNCATE` | `DELETE` | +| --------------------- | ----------------------------- | ------------------------- | +| Row Logging | No | Yes | +| Triggers | Not activated | Activated | +| Rollback | Not supported in many systems | Supported | +| Identity Column Reset | Yes | No | +| Performance | Faster | Slower for large datasets | ## Syntax @@ -43,7 +41,7 @@ TRUNCATE TABLE table_name; - `table_name`: Specifies the name of the table to truncate. -> **Note**: Use `TRUNCATE` carefully in production environments, as it cannot be undone. +> **Note:** Use `TRUNCATE` carefully in production environments, as it cannot be undone. ## Example