Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to create and delete tables in a test database while in development stage, but foreign keys verification bores me every time I need to erase its tables.

Is there any form to bypass this in Postgresql?

share|improve this question
    
Do you delete rows? Or do you drop the tables? It's unclear to me based on your question – a_horse_with_no_name Nov 7 '15 at 19:52
    
Hi @a_horse_with_no_name I hadn't seen your comment. I'm sorry if I was not clear. But I've solved. Thank you for your disposition. – Diego B. Sousa Nov 7 '15 at 19:57
up vote 0 down vote accepted

I've got it.

For a single table I can do:

DROP TABLE "tableName" CASCADE

For all tables inside a schema, for example "public", I can do:

DROP SCHEMA public CASCADE;
CREATE SCHEMA public;

Source:

http://www.postgresql.org/docs/current/static/sql-droptable.html

http://stackoverflow.com/a/13823560/937110

Or, as suggested by a_horse_with_no_name:

DROP OWNED BY name [, ...] [ CASCADE | RESTRICT ]

source: http://postgresql.org/docs/current/static/sql-drop-owned.html

share|improve this answer
1  
There is also drop owned by that drop all objects owned by a user. Are you really still using Postgres 8.2? – a_horse_with_no_name Nov 7 '15 at 20:32
    
I'm using PostgreSQL: 9.4.4 through PHPpgsql under Vagrant. I'm creating tables for testing and then I erase them. If you have a better solution I'm listening you. – Diego B. Sousa Nov 7 '15 at 21:06
    
Not necessarily better, but an alternative: postgresql.org/docs/current/static/sql-drop-owned.html – a_horse_with_no_name Nov 7 '15 at 21:11
    
It's a good alternative. Thank you @a_horse_with_no_name. I think I'll use this. – Diego B. Sousa Nov 7 '15 at 21:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.