Answers for "psql drop all tables if exits"

SQL
4

force drop all tables postgres

DROP SCHEMA public CASCADE;
CREATE SCHEMA public;
Posted by: Guest on November-26-2020
0

postgres drop all tables

DO $$ 
  DECLARE 
    r RECORD;
BEGIN
  FOR r IN 
    (
      SELECT table_name 
      FROM information_schema.tables 
      WHERE table_schema=current_schema()
    ) 
  LOOP
     EXECUTE 'DROP TABLE IF EXISTS ' || quote_ident(r.table_name) || ' CASCADE';
  END LOOP;
END $$ ;
Posted by: Guest on September-08-2021

Code answers related to "SQL"

Browse Popular Code Answers by Language