Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / DB2 Topics / March 2007

Tip: Looking for answers? Try searching our database.

how to remove everything related to a user(schema)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
%NAME% - 28 Mar 2007 16:14 GMT
is there a way to write a script  (not stored procedure) that looks
for all the
objects (triggers, events, materialized views, indexes, stats, tables)
created
by one user and remove them all?

thanks a lot
Michael Rudolph - 28 Mar 2007 16:37 GMT
Hi,

you didn't mention your DB2 version.

for V8.2.2 (FP9) see:
http://www-128.ibm.com/developerworks/db2/library/techarticle/dm-0602rielau/

for V9 see:
http://publib.boulder.ibm.com/infocenter/db2luw/v9/topic/com.ibm.db2.udb.admin.d
oc/doc/r0022036.htm


Regards
Michael
Ian - 28 Mar 2007 17:03 GMT
> is there a way to write a script  (not stored procedure) that looks
> for all the
> objects (triggers, events, materialized views, indexes, stats, tables)
> created
> by one user and remove them all?

Of course.  Serge Rielau wrote a nice set of stored procedures to
do all of this.

http://www-128.ibm.com/developerworks/db2/library/techarticle/dm-0602rielau/inde
x.html


If you really don't want a stored proc, you could take the logic out
of the 'dropschema' procedure.  You'd want to do something along the
lines of:

   -- Drop Views, MQTs, Tables (in that order)
   -- Generates 'drop table' statements
   select
      'drop table ' || rtrim(tabschema) || '.' || tabname
   from
      syscat.tables
   where
      tabschema = 'XXX"
   order by
      type desc;

You'd write similar statements for functions, procedures, sequences,
triggers, datatypes.
bwmiller16@gmail.com - 28 Mar 2007 17:18 GMT
> > is there a way to write a script  (not stored procedure) that looks
> > for all the
[quoted text clipped - 24 lines]
> You'd write similar statements for functions, procedures, sequences,
> triggers, datatypes.

This is what I have used in the past...(its not exactly what you want
but modifiable)...

select
'DROP '||
CASE
WHEN TYPE IN ('H','S','T','U') THEN 'TABLE '
WHEN TYPE IN ('V','W') THEN 'VIEW '
WHEN TYPE IN ('A') THEN 'ALIAS ' END
||RTRIM(TABSCHEMA) || '.' || RTRIM(tabname) ||';'
from
syscat.tables where tabschema = '$SCHEMA' and
tabname not like 'SYS%' order by tabschema, tabname
;
select
'DROP TRIGGER '||
RTRIM(TRIGSCHEMA) || '.' || RTRIM(trigname)||';'
from
syscat.triggers
where tabschema = '$SCHEMA' order by tabschema, tabname
;
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.