MySQL rename and indexes

der.hans PLUGd at LuftHans.com
Fri Nov 3 22:37:05 MST 2006


Am 03. Nov, 2006 schwätzte Alex Dean so:

>
> On Nov 3, 2006, at 7:58 PM, Alex Dean wrote:
>
>>
>> On Nov 3, 2006, at 6:35 PM, der.hans wrote:
>>
>>>> Any tips on creating a new table and indexes based on another
>>>> table and
>>>> its indexes?
>>
>> To create a new table based on an existing one, you can to this :
>> "CREATE TABLE new_table LIKE old_table"
>>
>> This is just the column and index information.  If you also want
>> the data, next do : "INSERT INTO new_table SELECT * FROM old_table"
>
> One caveat about that approach : The 'CREATE ... LIKE ...' will copy
> indexes, but it won't automatically copy any foreign keys you've
> defined.  You'd need to re-add them yourself.
>
> http://dev.mysql.com/doc/refman/5.0/en/create-table.html

What about the SHOW CREATE TABLE? Will that maintain everything about the
table structure? We're importing a new data set and previous code does a
"truncate table" then an import into the table. Since the report is live,
I'd rather avoid just whacking the data and hoping we can get the new data
in place...

CREATE TABLE `table_name` (
   `stuff1` int(9) NOT NULL default '0',
   `stuff2` char(1) NOT NULL default '',
   `stuff3` date NOT NULL default '0000-00-00',
   `stuff4` int(4) NOT NULL default '0',
   PRIMARY KEY  (`stuff1`),
   KEY `stuff2` (`stuff2`),
   KEY `stuff3` (`stuff3`),
   KEY `stuff4` (`stuff4`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |

That all looks correct to me. SHOW INDEX comes up with the same indexes as
the original table has.

danke,

der.hans
-- 
#  https://www.LuftHans.com/        http://www.CiscoLearning.org/
#  Sysdamin Days Phoenix, 6-7 Nov, now with edu discount  https://LOPSA.org/
#  Strangers are friends just waiting to happen!


More information about the PLUG-discuss mailing list