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 > Informix > Copy Table with content into new Table with different Name

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-01-06, 04:14
ArlanDirewolf ArlanDirewolf is offline
Registered User
 
Join Date: Oct 2005
Posts: 2
Copy Table with content into new Table with different Name

Hi,

What is the best way to "clone" a table and its contents into a new table with a different name. Is there a way to do it with the system tools or via some SQL-Statement?
Reply With Quote
  #2 (permalink)  
Old 06-01-06, 08:10
mjldba mjldba is offline
Registered User
 
Join Date: Dec 2003
Location: North America
Posts: 139
generate the schema for the table you want to clone, change the table-name and index-name(s) in the SQL script, and create a new table that will have exactly the same structure as the original table.

from the commandline execute this:
dbschema -d database_name -t table_name > build_table.sql

then edit the build_table.sql script as previously described and run it.

use you favorite SQL tool (like dbaccess) and execute this:

insert into new_table (col1, col2, col3, col4, col5, col6)
select (col1, col2, col3, col4, col5, col6)
from original_table

suggestion if the table is huge:
1) execute the "create table" statement in build_table.sql to create the new table
2) insert data into the new table from the original table as described
3) execute the "create index" statement(s) in build_table.sql
Reply With Quote
  #3 (permalink)  
Old 06-01-06, 08:19
ArlanDirewolf ArlanDirewolf is offline
Registered User
 
Join Date: Oct 2005
Posts: 2
That solved the issue - Thanks for your help
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