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 > Schema Change

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-04-09, 03:02
ratheeshknair ratheeshknair is offline
Registered User
 
Join Date: Jan 2009
Posts: 153
Schema Change

Hi Experts,

How to change the schema name of an object??

Now all my object are under administrator schema...I want to change all the objects from admnistrator schema to user1 and in another database i want to change schema of some particular objects ..

How can i achieve this??
Reply With Quote
  #2 (permalink)  
Old 05-04-09, 03:24
rahul_s80 rahul_s80 is offline
Registered User
 
Join Date: Jul 2006
Location: Pune , India
Posts: 433
Admin_copy_schema
__________________
Rahul Singh
Certified DB2 9 DBA / Application Developer
Reply With Quote
  #3 (permalink)  
Old 05-05-09, 01:37
ratheeshknair ratheeshknair is offline
Registered User
 
Join Date: Jan 2009
Posts: 153
Hi,

When I tried I am getting error.

ADMIN_COPY_SCHEMA(administrator,appuser,copy,rknai r,userspace1,userspace1, error_table_schema, error_table_name)
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 "(" was found following "ADMIN_COPY_SCHEMA".
Expected tokens may include: "DELIMITED_TYPE_IDENTIFIER". SQLSTATE=42601

SQL0104N An unexpected token "(" was found following "ADMIN_COPY_SCHEMA". Expected tokens may include: "DELIMITED_TYPE_IDENTIFIER
Reply With Quote
  #4 (permalink)  
Old 05-05-09, 01:47
rahul_s80 rahul_s80 is offline
Registered User
 
Join Date: Jul 2006
Location: Pune , India
Posts: 433
chk for syntax of procedure call
__________________
Rahul Singh
Certified DB2 9 DBA / Application Developer
Reply With Quote
  #5 (permalink)  
Old 05-05-09, 03:11
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
something like this:

connect to sample;
call ADMIN_COPY_SCHEMA('administrator','appuser','copy' ,'rknai r','userspace1','userspace1', 'error_table_schema', 'error_table_name');
__________________
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 05-05-09, 03:30
ratheeshknair ratheeshknair is offline
Registered User
 
Join Date: Jan 2009
Posts: 153
HI Rahul & Marcus ,

Thanks for the quick reply..

I am a newbie to DB2 can u please tell me what exactly i have to do...

My requiremnet is to change the schema from administrator to appuser..

TIA
Reply With Quote
  #7 (permalink)  
Old 05-05-09, 07:25
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
You can use the admin_copy_schema stored procedure to help you with renaming (it actually copies) the schema. Please refer to the following URLs for more info:
IBM DB2 9.5 Information Center for Linux, UNIX, and Windows
Conveniently create new versions of your database objects


Here is an example of copying schema 'TEST' to TEST2':

test@p6db2serv /home/test > db2 "call SYSPROC.ADMIN_COPY_SCHEMA ('TEST','TEST2','COPY', NULL, NULL, NULL, 'COPYSCHEMA', 'COPYERROR')"

Value of output parameters
--------------------------
Parameter Name : ERRORTABSCHEMA
Parameter Value : COPYSCHEMA

Parameter Name : ERRORTABNAME
Parameter Value : COPYERROR

Return Status = 0


Note: admin_copy_schema needs to use the systoolspace tablespace. If you don't have it, it needs to created prior to using the procedure. Here is an example of creating it in an automatic storage db:

test@p6db2serv /home/test > db2 "CREATE TABLESPACE SYSTOOLSPACE MANAGED BY AUTOMATIC STORAGE EXTENTSIZE 4"
DB20000I The SQL command completed successfully.



The old schema can be removed using the admin_drop_schema stored procedure. Here is an example:

test@p6db2serv /home/test > db2 "CALL SYSPROC.ADMIN_DROP_SCHEMA('TEST', NULL, 'ERRORSCHEMA', 'ERRORTABLE')"

Value of output parameters
--------------------------
Parameter Name : ERRORTABSCHEMA
Parameter Value : ERRORSCHEMA

Parameter Name : ERRORTAB
Parameter Value : ERRORTABLE

Return Status = 0


Please check the restrictions/usage notes in the manual. I'd highly recommend taking a backup prior to copying/dropping the schema if this is an important database (just in case something happens).
Reply With Quote
  #8 (permalink)  
Old 05-06-09, 00:59
ratheeshknair ratheeshknair is offline
Registered User
 
Join Date: Jan 2009
Posts: 153
Thanks Bella
Reply With Quote
  #9 (permalink)  
Old 05-06-09, 01:12
ratheeshknair ratheeshknair is offline
Registered User
 
Join Date: Jan 2009
Posts: 153
Hi Bella ,

Wheni tried to execute the command I am getting error

db2 => call SYSPROC.ADMIN_COPY_SCHEMA ('administrator','appuser','COPY', NULL,N
ULL, NULL, 'COPYSCHEMA', 'COPYERROR')
SQL0443N Routine "*MIN_COPY_SCHEMA" (specific name "") has returned an error
SQLSTATE with diagnostic text "Source schema does not exist, or contains no
objects". SQLSTATE=38000


All user tables are under administrator schema...

TIA
Reply With Quote
  #10 (permalink)  
Old 05-06-09, 07:39
rahul_s80 rahul_s80 is offline
Registered User
 
Join Date: Jul 2006
Location: Pune , India
Posts: 433
error code signal a lot. see if 'administrator' exists
rather chk for schema in upper case
__________________
Rahul Singh
Certified DB2 9 DBA / Application Developer
Reply With Quote
  #11 (permalink)  
Old 05-06-09, 08:11
ratheeshknair ratheeshknair is offline
Registered User
 
Join Date: Jan 2009
Posts: 153
Thanks Rahul,

It worked
Reply With Quote
  #12 (permalink)  
Old 07-08-09, 16:07
MarkhamDBA MarkhamDBA is offline
Registered User
 
Join Date: Dec 2008
Location: Toronto, Canada
Posts: 381
change schema for tables

db2 v8.2 on AIX 5/db2 v9.5 on AIX 6
We need to change schema for abt 200 db2 tables (containing data) from AAA to BBB.

db2move seem like a good idea but it's working only between databases.

Looks like admin_copy_schema does it within same database, but I need to copy tables data and rename indexes schemas as well. How and can I use it for this purpose? I guess we would have to drop existing packages and recreate them for new schema as this is a condition for this API.

The database is on v8.2 now so I am thinking we might have to wait till we upgrade to v9.5 and then do it.

Any thoughts?
__________________
DB2 v9.5 ESE on AIX v6.1/ v9./10 on z/OS
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