开发者

PostgreSQL: purge all tables [duplicate]

This question already has answers here: 开发者_JAVA百科 Closed 12 years ago.

Possible Duplicate:

How to empty a SQL database?

What is the fastest way to delete all records from all tables in the db supposing they do not have too much data(may be a few records in some tables but no more)?

I believe that recreate the database from structure dump is much longer variant.


TRUNCATE TABLE name1, name2, ... CASCADE

TRUNCATE quickly removes all rows from a set of tables. It has the same effect as an unqualified DELETE on each table, but since it does not actually scan the tables it is faster. This is most useful on large tables.

If you have a lot of tables you might want to query for the list of tables and construct the truncate query dynamically, but for a small number of tables you could just type the names in by hand.

See this post for information on selecting all tables and running a query dynamically. The example given is for grantall but the idea is the same.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜