Skip to content
Closed
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 65 additions & 1 deletion docs/sql-ref-syntax-ddl-truncate-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,68 @@ license: |
limitations under the License.
---

**This page is under construction**
### Description
The `TRUNCATE TABLE` statement removes all the rows from a table or partition(s). The table must not be a view
or an external/temporary table. Inorder to truncate multiple partitions at once, user can specify the partitions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inorder -> In order
user -> the user
back-tick partition_spec

in partition_spec. If no partition_spec is specified it will remove all partitions in the table.

### Syntax
{% highlight sql %}
TRUNCATE TABLE table_name [PARTITION partition_spec];
{% endhighlight %}

### Parameters
<dl>
<dt><code><em>table_name</em></code></dt>
<dd>The name of an existing table.</dd>
</dl>

<dl>
<dt><code><em>PARTITION ( partition_spec :[ partition_column = partition_col_value, partition_column = partition_col_value, ...] )</em></code></dt>
<dd>Specifies one or more partition column and value pairs. The partition value is optional.</dd>
</dl>


### Examples
{% highlight sql %}

--Create table Student with partition
CREATE TABLE Student ( name String, rollno INT) PARTITIONED BY (age int);

SELECT * from Student;
+-------+---------+------+--+
| name | rollno | age |
+-------+---------+------+--+
| ABC | 1 | 10 |
| DEF | 2 | 10 |
| XYZ | 3 | 12 |
+-------+---------+------+--+

-- Removes all rows from the table in the partion specified
TRUNCATE TABLE Student partition(age=10);

--After truncate execution, records belonging to partition age=10 is removed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is -> are

SELECT * from Student;
+-------+---------+------+--+
| name | rollno | age |
+-------+---------+------+--+
| XYZ | 3 | 12 |
+-------+---------+------+--+

-- Removes all rows from the table from all partitions
TRUNCATE TABLE Student;

SELECT * from Student;
+-------+---------+------+--+
| name | rollno | age |
+-------+---------+------+--+
+-------+---------+------+--+
No rows selected

{% endhighlight %}


### Related Statements
- [DROP TABLE](sql-ref-syntax-ddl-drop-table.html)
- [ALTER TABLE](sql-ref-syntax-ddl-alter-tabley.html)