How to empty a SQL database? -


I am looking for a simple way to delete all data from a database and to structure (table, connection, etc.) ..). I am using postgreSQL but I think if there is a command to do this then it is not specific to postgrads.

Thank you,

pg_dump code>. Drop the database, recreate it and load the schema.

Dump the database schema (-s tag) into one file:

  pg_dump -s -f db.dump db-NAME  

Delete the database:

  dropdb DB-NAME  

make it happy:

  createdb DB-NAME  

Reinstall the schema only:

  pg_restore db.dump & gt; Psql DB-NAME  

This should work on PostgreSQL; For this, other DBMSs can have their own devices

Edit:

For the following comments, you can use the dropdb command, And just create another database with the dump schema if everything went well, then you can leave the old database:

  pg_dump -s -f db.dump db-NAME Created DB-New-name pg_restore db.dump & gt; Psql DB-NEW-NAME  

At this point, you have full database on DB-NAME, and there is a blank schema on DB-New-NAME. After you are sure everything is okay, use dropdb DB-NAME .


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -