Monday, 19 June 2017

Script to Drop a user's objects.

This script will produce the alter/drop commands that we can use to drop all the user objects from a database.


REM Script to drop all user objects

SET LINES 132 PAGES 59 FEEDBACK OFF ECHO OFF VERIFY OFF
BREAK ON username
TTITLE left _date center 'SQL To Drop A Users Objects' skip 2

PROMPT When prompted, enter the name of the user who''s objects you wish to drop
PROMPT Then cut and paste the commands presented to drop those objects.

SELECT 'alter table '
|| owner
|| '.'
|| table_name
|| ' drop constraint '
|| constraint_name
|| ' cascade;' code
FROM dba_constraints
WHERE (constraint_type = 'R') AND (owner = UPPER ('&&enter_user_name'))
UNION
SELECT DISTINCT 'DROP '
|| object_type
|| ' '
|| owner
|| '.'
|| object_name
|| ';' code
FROM dba_objects
WHERE (object_type NOT IN ('INDEX'))
AND (owner = UPPER ('&&enter_user_name'))
ORDER BY code DESC;


Sample Output

SQL> When prompted, enter the name of the user who’s objects you wish to drop
SQL> Then cut and paste the commands presented to drop those objects.

18-JUL-08 SQL To Drop A Users Objects

CODE
--------------------------------------------------------------------------------------
DROP TABLE SCOTT.UMCATEGORYCONVFACTOR;
DROP TABLE SCOTT.UOMCATEGORYCONVFACTOR;
DROP TABLE SCOTT.UDT_SOURCING;
DROP TABLE SCOTT.WEBSPRELOPTS;
DROP TABLE SCOTT.WEBSKUOPTS;
DROP TABLE SCOTT.WDDDATA;





I hope this article helped you. Your suggestions/feedback are most welcome.

Keep learning... Have a great day!!!



11 comments:

  1. This information you provided in the blog that is really unique I love it!! Thanks for sharing such a great blog. Keep posting..
    Oracle DBA training
    Oracle DBA course
    Oracle DBA training institute

    ReplyDelete
  2. Thanks for sharing this valuable information and we collected some information from this post.

    Corporate training in Machine learning

    ReplyDelete
  3. Thanks for posting this blog. I really love while reading it.

    Python Corporate training in Nigeria

    ReplyDelete
  4. The Content is very Attractive and The Way of Explaining About the Topic is Very Clear..It's very Easy to Understand...Keep Doing this Amazing Work
    Java training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery

    ReplyDelete
  5. This blog very easily understandable. Thanks for sharing such an informative post with us. This is a nice post in an interesting line of content.
    Oracle DBA Training in Bangalore

    ReplyDelete