SELECT INTO 語句:表示從一個表中選取數據,然后把數據插入另一個表中,常用來備份一張表
1.全表結構備份:
SELECT * INTO new_table_name
FROM old_tablename;
示例:備份student表,備份表取名為student_backup
select * into student_backup
from student ;
則會生成一張與student表結構及數據一樣的備份表。
2.如果只備份表中的某些列:
SELECT column_name1,column_name2... INTO new_table_name FROM old_tablename
示例:只備份student表中的sno,name列入新表student_backup
select sno,name into student_backup
from student ;
3.如果需要將表中滿足一定條件的記錄進行備份,則可以使用where字句配套使用
示例:將所有性別為男的學生記錄備份到新表student_backup
select * into student_backup
from student
where sex='男';
注:但是在mysql中使用SELECT INTO語句是無法進行備份操作,執行命令時會提示新表未定義

所以,我們應該使用下列語句進行數據表的備份操作。
1.只復制表結構到新表 :(只有結構無數據)
create table 新表 select * from 舊表 where1=2
或create table 新表 like 舊表
此兩種方法的區別:使用第一條語句,備份的新表並沒有舊表的primary key 、auto_increment等屬性,需要重新對新表進行設置
示例:create table newstudent select * from student where 1=2;

或者 create table newstudent like sutdent;
2.復制表結構及數據到新表
create table 新表 select * from 舊表;---這種方法會將oldtable中所有的內容都拷貝過來,同時也存在備份的新表不具備舊表 primary key、auto_increment等屬性,需要對新表再次設置。
示例:復制student表中所有數據到新表student_backup1;
create table student_backup1 select * from student;