If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > How to drop a schema/user from db2 command line

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-12-04, 16:19
jpleau jpleau is offline
Registered User
 
Join Date: Feb 2004
Posts: 3
How to drop a schema/user from db2 command line

Hi All,

I am running DB2 7.2.5 on Windows 2000 server and want to create a sql script that users can run to drop their schema. This is useful as I work in a test lab and schemas regularly have to be dropped to create a clean environment.

I tried using DROP SCHEMA xxx RESTRICT, but get an error becuase there are objects in the schema. Is there a way to tell db2 (using SQL) to drop all objects in the schema? I have similar scripts for Oracle, using DROP USER CASCADE, but can't seem to find an equivalent statement in DB2.

Any ideas? The script can either drop the schema or drop the user and recreate it.

Thanks
JP
Reply With Quote
  #2 (permalink)  
Old 02-12-04, 16:34
Marcus_A Marcus_A is online now
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Your script could read the catalog and find out what objects belong to the schema and then drop them.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 02-13-04, 08:50
jpleau jpleau is offline
Registered User
 
Join Date: Feb 2004
Posts: 3
So there is no single command that can accomplish it? If the script has to query the catalog first, would there have to be a different drop statement for each type of objects?

Thanks
JP
Reply With Quote
  #4 (permalink)  
Old 02-13-04, 08:58
Marcus_A Marcus_A is online now
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Some drops may automatically drop dependent objects, but I am not sure which ones. Consult the documentation or run some tests.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #5 (permalink)  
Old 02-13-04, 09:04
Marcus_A Marcus_A is online now
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
I checked the SQL Reference. Why are you using RESTRICT?

The RESTRICT keyword enforces the rule that no objects can be defined in the specified schema for the schema to be deleted from the database SQLSTATE 42893).
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #6 (permalink)  
Old 02-13-04, 09:32
jpleau jpleau is offline
Registered User
 
Join Date: Feb 2004
Posts: 3
If I try without restrict, I get the error

DB21034E The command was processed as an SQL statement because it was not a valid Command Line Processor command. During SQL processing it returned: SQL0104N An unexpected token "END-OF-STATEMENT" was found following "drop schema qa6". Expected tokens may include: "RESTRICT". SQLSTATE=42601

Are there any other options other than RESTRICT?
Reply With Quote
  #7 (permalink)  
Old 02-13-04, 09:39
Marcus_A Marcus_A is online now
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
You are correct that the RESTRICT keyword is required.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On