MySQL複製表-SELECT INTO FROM

來源:互聯網
上載者:User

標籤:log   gui   str   mysql   語句   ast   order   csharp   extra   

基礎Table:

mysql> select * from staff;+----+----------+-------+| id | name     | slary |+----+----------+-------+|  3 | haofugui | 10000 ||  4 | guoming  |  3500 ||  5 | haotian  |  2900 |+----+----------+-------+3 rows in set (0.00 sec)mysql> describe staff;+-------+----------+------+-----+---------+----------------+| Field | Type     | Null | Key | Default | Extra          |+-------+----------+------+-----+---------+----------------+| id    | int(11)  | NO   | PRI | NULL    | auto_increment || name  | char(20) | YES  |     | NULL    |                || slary | int(11)  | YES  |     | NULL    |                |+-------+----------+------+-----+---------+----------------+3 rows in set (0.00 sec)

 

語句1:SELECT [field1, field2 | *] into Table2 [IN externaldatabase] from Table1 where condition;

語句2:SELECT A.field1,B.field2 into C [IN externaldatabase] from A [inner | left | right] join B on [condition1] where condition2;

說明:[IN externaldatabase]可以實現跨資料庫的資料複製。

注意:目標表(即Table2或C)不要存在,MySQL會自動建立,這是與INSERT INTO SELECT的一個很大的不同點。

 

樣本:

mysql> SELECT * INTO Persons_backup FROM Persons;

 

mysql> SELECT *      //跨資料庫的資料複製    -> INTO Persons IN ‘Backup.mdb‘    -> FROM Persons;

  

mysql> SELECT LastName,FirstName    -> INTO Persons_backup    -> FROM Persons;

  

mysql> SELECT LastName,Firstname    -> INTO Persons_backup    -> FROM Persons    -> WHERE City=‘Beijing‘;

  

mysql> SELECT Persons.LastName,Orders.OrderNo  //表串連複製,即多表複製    -> INTO Persons_Order_Backup    -> FROM Persons    -> INNER JOIN Orders    -> ON Persons.Id_P=Orders.Id_P;

  

MySQL複製表-SELECT INTO FROM

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.