diff --git a/README.md b/README.md index 496bb7d..be6d195 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,7 @@ smart people at [Hashrocket](http://hashrocket.com/). - [Temporary Tables](postgres/temporary-tables.md) - [Timestamp Functions](postgres/timestamp-functions.md) - [Toggling The Pager In PSQL](postgres/toggling-the-pager-in-psql.md) +- [Truncate All Rows](postgres/truncate-all-rows.md) - [Turning Timing On](postgres/turning-timing-on.md) - [Types By Category](postgres/types-by-category.md) - [Use Argument Indexes](postgres/use-argument-indexes.md) diff --git a/postgres/truncate-all-rows.md b/postgres/truncate-all-rows.md new file mode 100644 index 0000000..bc1d36b --- /dev/null +++ b/postgres/truncate-all-rows.md @@ -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)