본문 바로가기

카테고리 없음

postgresql 테이블 모두 삭제

테이블 날리기

---SELECT tablename FROM pg_tables WHERE schemaname = current_schema()

DO $$ DECLARE
    r RECORD;
BEGIN
    -- if the schema you operate on is not "current", you will want to
    -- replace current_schema() in query with 'schematodeletetablesfrom'
    -- *and* update the generate 'DROP...' accordingly.
    FOR r IN (SELECT tablename FROM pg_tables WHERE schemaname = current_schema()) LOOP
        EXECUTE 'DROP TABLE IF EXISTS ' || quote_ident(r.tablename) || ' CASCADE';
    END LOOP;
END $$;

---SELECT tablename FROM pg_tables WHERE schemaname = current_schema()

삭제

DO $$ DECLARE
    r RECORD;
BEGIN
    -- if the schema you operate on is not "current", you will want to
    -- replace current_schema() in query with 'schematodeletetablesfrom'
    -- *and* update the generate 'DROP...' accordingly.
    FOR r IN (SELECT tablename FROM pg_tables WHERE schemaname = current_schema()) LOOP
        EXECUTE 'DELETE FROM  ' || quote_ident(r.tablename) ;
    END LOOP;
END $$;

 



참고

www.lesstif.com/dbms/postgresql-drop-table-61906474.html