關於Mysql 複製表與結構

來源:互聯網
上載者:User

一、CREATE TABLE 方法

整表複製 # create table 新表 select * from 舊錶;
結構複製 # create table 新表 select * from 舊錶 where 1<>1;

二、INSERT INTO 方法

得到建表語句 # show create table 舊錶;
建立表
複製資料到新表 # insert into 新表 select * from 舊錶;

如果原表有一個欄位是ID,主鍵,自動增加,則這個欄位的屬性不能被完全複製,需要如下語句

ALTER TABLE `reserve_table_dc3` ADD PRIMARY KEY(`ID`)

ALTER TABLE `reserve_table_storage` CHANGE `ID` `ID` INT( 32 ) NOT NULL AUTO_INCREMENT

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.