How to delete all tables from database
By Pravin•
Many times when we are working in development environment, we would like to recreate all tables from schema, we can use below query to drop all tables.
please be cautious while running this query, you will loose all your data from database, recommended only for local and dev servers.
DO $$ DECLARE v_table_name TEXT; -- Changed variable name to avoid conflict BEGIN FOR v_table_name IN (SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_type = 'BASE TABLE') LOOP EXECUTE 'DROP TABLE IF EXISTS public.' || quote_ident(v_table_name) || ' CASCADE'; END LOOP; END $$;
Comments
No comments yet. Be the first to comment!
Leave a Comment
Your comment will be visible after approval.