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 > Move Table to another Table Space

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-05-05, 23:12
ggnanaraj ggnanaraj is offline
Registered User
 
Join Date: Aug 2002
Location: Chennai, India
Posts: 171
Move Table to another Table Space

Need to reorganize tables into different table spaces based on the size of the tables. As far as I am aware, you need to drop and recreate the table in the new table space in DB2 UDB. You can however, alter the buffer pool allocated to the table space. DB2 UDB does not provide a ALTER TABLE command to move a table to another table space like Oracle.

Pls correct me if I am wrong.

TIA.
Reply With Quote
  #2 (permalink)  
Old 12-06-05, 01:00
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
You are correct. You cannot alter a table to define a new tablespace location. But you do the following:

Create a new table like the old one (CREATE LIKE) and specify the new tablespace location. Use the same schema name, but a different table name.

Move the data with a INSERT INTO new-table SELECT * FROM old-table

Rename the old table to something different.

Rename the new table to the name of the old table.

Create any Primary and foreign keys as exist in the old table. Create any other indexes that exist on the old table.

Drop the old table.

Check out the SQL Reference Vol 2 manual for exact syntax.
__________________
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-12, 12:18
fudge21 fudge21 is offline
Registered User
 
Join Date: Feb 2012
Posts: 3
How would we copy the constaints the old table had?
Reply With Quote
  #4 (permalink)  
Old 02-13-12, 12:44
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
By using db2look to extract their definition, then running the resulting script.
Reply With Quote
  #5 (permalink)  
Old 02-13-12, 12:51
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
If you happen to be on DB2 9.7, you can use ADMIN_MOVE_TABLE procedure.

HTH

Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #6 (permalink)  
Old 02-13-12, 12:54
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by sathyaram_s View Post
use ADMIN_MOVE_TABLE procedure.
Not really. It does not move referential integrity constraints, as far as I know.
Reply With Quote
  #7 (permalink)  
Old 02-13-12, 14:22
fudge21 fudge21 is offline
Registered User
 
Join Date: Feb 2012
Posts: 3
Sorry, generating the DDL and using it on the new table doesn't allow me to remove the old one. the constraints are still there
Reply With Quote
  #8 (permalink)  
Old 02-13-12, 23:04
ggnanaraj ggnanaraj is offline
Registered User
 
Join Date: Aug 2002
Location: Chennai, India
Posts: 171
To remove the old constraints, you would need to drop them via an ALTER TABLE statement.

To recap, if the objective is to move a table from one table space to another, you would need to do the following (one of the methods):
Create a new table like the old one (CREATE LIKE) and specify the new tablespace location. Use the same schema name, but a different table name.

Move the data with a INSERT INTO new-table SELECT * FROM old-table

Rename the old table to something different.

Rename the new table to the name of the old table.

Create any Primary and foreign keys as exist in the old table. Create any other indexes that exist on the old table. db2look can be used for this.

Drop the old table.
Hope this helps.
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