Home » SQL & PL/SQL » SQL & PL/SQL » how can i delete all tables in a user
how can i delete all tables in a user [message #7901] Wed, 16 July 2003 06:03 Go to next message
Rehman
Messages: 19
Registered: February 2000
Junior Member
how can i delete all tables in a user
Re: how can i delete all tables in a user [message #7903 is a reply to message #7901] Wed, 16 July 2003 08:44 Go to previous messageGo to next message
Geoffrey
Messages: 32
Registered: February 2002
Member
you can create a script using this sql

SELECT
'drop ' || object_type || ' ' || object_name || decode(object_type,
'TABLE',
' CASCADE CONSTRAINTS') || ';'
FROM
dba_objects
WHERE
object_type = 'TABLE' and
owner = 'USERNAME'
Re: how can i delete all tables in a user [message #7904 is a reply to message #7903] Wed, 16 July 2003 09:20 Go to previous messageGo to next message
Rehman
Messages: 19
Registered: February 2000
Junior Member
when iam trying to delete it shows error
my user not a dba

dba_objects
*
ERROR at line 6:
ORA-00942: table or view does not exist
Re: how can i delete all tables in a user [message #7912 is a reply to message #7904] Wed, 16 July 2003 19:26 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9090
Registered: November 2002
Location: California, USA
Senior Member
If you are just trying to delete from your own schema, you can use user_objects instead of dba_objects.
Re: how can i delete all tables in a user [message #7931 is a reply to message #7912] Thu, 17 July 2003 02:25 Go to previous messageGo to next message
Rehman
Messages: 19
Registered: February 2000
Junior Member
while iam in system/manger
-----------------------------
1 SELECT
2 'drop ' || object_type || ' ' || object_name || decode(object_type,
3 'TABLE',
4 ' CASCADE CONSTRAINTS') || ';'
5 FROM
6 dba_objects
7 WHERE
8 object_type = 'TABLE' and
9* owner = 'rehman'
SQL> /

no rows selected
-------------------------
In current User The result is

------------------------------------------------------------------------
'DROP'||OBJECT_TYPE||''||OBJECT_NAME||DECODE(OBJECT_TYPE,'TABLE','CASCADECONSTRA
--------------------------------------------------------------------------------
drop TABLE RRT CASCADE CONSTRAINTS;
drop TABLE RRTR CASCADE CONSTRAINTS;
drop TABLE TT CASCADE CONSTRAINTS;


tables are not delted
Re: how can i delete all tables in a user [message #7949 is a reply to message #7931] Thu, 17 July 2003 18:10 Go to previous message
Barbara Boehmer
Messages: 9090
Registered: November 2002
Location: California, USA
Senior Member
You need to spool to a sql file, then start that file, so that the commands that you see are run and the tables are dropped:

STORE SET saved_settings REPLACE
SET ECHO OFF FEEDBACK OFF HEADING OFF PAGESIZE 0 SERVEROUTPUT ON VERIFY OFF WRAP ON
SPOOL drop_tables.sql
SELECT 'DROP ' || object_type || ' ' || object_name
|| DECODE (object_type, 'TABLE', ' CASCADE CONSTRAINTS' || ';'
FROM dba_objects WHERE object_type = 'TABLE' AND owner = 'rehman';
SPOOL OFF
START saved_settings.sql
START drop_tables.sql
Previous Topic: SQL challenge to any gurus out there
Next Topic: query
Goto Forum:
  


Current Time: Tue Apr 23 20:11:51 CDT 2024