1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-06 16:48:01 +00:00

Add Truncate All Rows as a postgres til.

This commit is contained in:
jbranchaud
2015-11-07 17:20:17 -06:00
parent e7c2f87feb
commit 96f7c14079
2 changed files with 22 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
# Truncate All Rows
Given a postgres database, if you want to delete all rows in a table, you
can use the `DELETE` query without any conditions.
```
> delete from pokemons;
DELETE 151
```
Though `DELETE` can do the job, if you really are deleting all rows to clear
out a table, you are better off using `TRUNCATE`. A `TRUNCATE` query will be
faster than a `DELETE` query because it will just delete the rows without
scanning them as it goes.
```
> truncate pokemons;
TRUNCATE TABLE
```
[source](http://www.postgresql.org/docs/8.2/static/sql-truncate.html)