当前位置:Gxlcms > 数据库问题 > SQL语句之备份表

SQL语句之备份表

时间:2021-07-01 10:21:17 帮助过:4人阅读

  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;

技术分享图片

技术分享图片

SQL语句之备份表

标签:无数据   执行   where   test   htm   back   name   语句   两种   

人气教程排行