How to drop all user tables?

前端 未结 9 577
后悔当初
后悔当初 2020-12-04 04:22

How can I drop all user tables in oracle?

I have problem with constraints. When I disable all it is still no possible.

9条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-04 05:11

    Another answer that worked for me is (credit to http://snipt.net/Fotinakis/drop-all-tables-and-constraints-within-an-oracle-schema/)

    BEGIN
    
    FOR c IN (SELECT table_name FROM user_tables) LOOP
    EXECUTE IMMEDIATE ('DROP TABLE "' || c.table_name || '" CASCADE CONSTRAINTS');
    END LOOP;
    
    FOR s IN (SELECT sequence_name FROM user_sequences) LOOP
    EXECUTE IMMEDIATE ('DROP SEQUENCE ' || s.sequence_name);
    END LOOP;
    
    END;
    

    Note that this works immediately after you run it. It does NOT produce a script that you need to paste somewhere (like other answers here). It runs directly on the DB.

提交回复
热议问题