cancel
Showing results for 
Search instead for 
Did you mean: 

Rename table in DB2

former_member185031
Active Contributor
0 Kudos

Hello Guys,

I am trying to rename a table in db2 which is not part of any schema. Unfortunately i am not able to it. I tried everything but it is not working. What i am doing wrong here ?

My DB2 version is 9.7

db2 => rename table QCM8/B28/XT6D64T to /B28/XT6D64T1

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 "rename table" was found following "BEGIN-OF-STATEMENT".  Expected tokens may include:  "<values>".

SQLSTATE=42601

Regards,

Subhash

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Subhash

For renaming the table , you need to run the command as :

RENAME TABLE <schema_name>.<table_name> TO <new_name>

Please see the link below

http://publib.boulder.ibm.com/infocenter/db2luw

/v9/index.jsp?topic=%2Fcom.ibm.db2.udb.admin.doc%2Fdoc%2Ft0005369.htm

For finding the schema name of the table :

db2 " select tabschema from syscat.tables where tabname = 'table name' "


Thanks


Rishi

former_member185031
Active Contributor
0 Kudos

Thanks Rishi for your response.

This is the error I am getting. I don't know what I am missing here.

db2 => select tabschema from syscat.tables where tabname='QCM8/B28/XT6D64T'

TABSCHEMA                                                                      
--------------------------------------------------------------------------------------------------------------------------------
SAPBQ1                                                                         

  1 record(s) selected.

db2 => RENAME TABLE SAPBQ1.QCM8/B28/XT6D64T TO SAPBQ1./B28/XT6D64T1
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 "RENAME TABLE SAPBQ1.QCM8/B28/XT6D64T TO SA" was
found following "BEGIN-OF-STATEMENT".  Expected tokens may include:
"<values>".  SQLSTATE=42601
db2 =>

Regards,

Subhash

Former Member
0 Kudos

Hi Subhash

Please use the following query directly :

RENAME TABLE "SAPBQ1.'QCM8/B28/XT6D64T'" TO "SAPBQ1.'/B28/XT6D64T1'"

Looks like the error you got is due to the table name ( containing character / )  and the format to be used while running query in SQL.

Thanks

Rishi

Answers (1)

Answers (1)

0 Kudos

Is your issue resolved subhash ?