0
0
Fork 0
zblog/content/post/50.md

28 lines
919 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

+++
title = "Alle Tabellen einer DB loeschen mit PostgreSQL 9.0"
date = "2010-09-30T21:21:00+00:00"
author = "Gibheer"
draft = false
+++
Mit Version 9.0 der open source Datenbank [PostgreSQL (PostgreSQL: The
worlds most advanced open source database)](http://postgresql.org)
wurde die Möglichkeit geschaffen [anonyme Codeblöcke
(PostgreSQL 9.0 - Do
Statements)](http://www.postgresql.org/docs/current/interactive/sql-do.html)
auszuführen.
Das habe ich mir eben mal zu nutze gemacht und ein kleines Script
geschrieben, welche mir alle Tabellen aus einer Datenbank löscht.
<source:sql>DO \$\$declare i record;\
begin\
for i in (select tablename from pg\_tables where schemaname = public)
loop\
execute drop table||i.tablename||cascade;\
end loop;\
end\$\$;</source>
Dieses Script l&auml;sst sich in psql ausf&uuml;hren. Viel Spass mit dem
neuen Feature und beim ausprobieren.