資料表資料遷移 複製乙個表的資料到另外乙個表

2021-08-28 10:10:58 字數 555 閱讀 4900

通過 sql,你可以從乙個表複製資訊到另乙個表。

mysql 資料庫不支援 select ... into 語句,但支援 

insert into ... select

。select into 語句從乙個表複製資料,然後把資料插入到另乙個新錶中。

create  table 新錶  as select * from 舊表

我們可以複製所有的列插入到新錶中:

select * into newtable from oletable;

或者只複製希望的列插入到新錶中:

select  name,***,age into newtable from oldtable

insert into select 語句從乙個表複製資料,然後把資料插入到乙個已存在的表中。(所以要先新建一張表)

insert into 新錶 select * from 舊表;

或者我們可以只複製希望的列插入到另乙個已存在的表中:

insert into 新錶(欄位1,欄位2,欄位n)  select  欄位1,欄位2,欄位n from 舊表 ;

MySQL複製資料表

主題 下面是我在複製表結構以及資料時最常使用的搭配 table new 新錶 table old 原表 create table new like table old 完整複製原表的建表語句以建立新錶 insert into table new select from table old 完整複製原...

MySQL 複製資料表

假設現在有張資料表 users create table users userid int 10 unsigned not null username varchar 100 unique passwd varchar 100 default 123456 primary key userid en...

複製資料表到新的表

分為兩種情況,一種是目標表不存在,另一種是目標表已存在,語法是不同的。分別以sqlserver和oracle為例,兩者略有不同。sqlserver中,如果目標表不存在 1 select into新錶名from舊表名 sqlserver中,如果目標表已存在 1 insertinto新錶名select ...