当前位置:网站首页>How to copy table structure and table data in MySQL
How to copy table structure and table data in MySQL
2022-07-30 19:40:00 【asdfadafd】
1, copy table structure and data to new table
create table new_table_name select * from old_table_name;One of the worst aspects of this method is that the new table does not have the primary key, Extra (auto_increment) and other attributes of the old table.
2, only copy the table structure to the new table
create table new_table_name select * from old_table_name where 1=2;or
create table new_table_name like old_table_name;3. Copy the data of the old table to the new table (assuming the two tables have the same structure)
insert into new_table_name select * from old_table_name;4. Copy the data from the old table to the new table (assuming the two tables have different structures)
insert into new_table_name(field1,field2,field3) select (field1,field2,field3) from old_table_name;5. The tables are not in the same database (eg: db1 table1, db2 table2)
Full copy
insert into db1.table1 select * from db2.table2;Do not copy duplicate records
insert into db1.table1 select distinct* from db2.table2;Copy the first 10 records
insert into db1.table1 select 10* from db2.table2;6. View the SQL created for the table
show create table table_name;This will list the table's creation SQL.We just need to copy the SQL and change the table_name to create an identical table.
7. Clear table data
delete from table_name;or
truncate table table_name;The delete statement without the where parameter can delete all the contents in the mysql table;
Use truncate table to also clear all the contents in the mysql table.
But using delete to clear the records in the table, the ID of the content is still established from the ID of the deletion point instead of starting from 1.
And truncate is equivalent to preserving the structure of the table and re-establishing a new same table.
Truncate is faster than delete in efficiency.
But mysql log is not recorded after truncate is deleted, and data cannot be recovered.
The effect of delete is a bit like deleting all records in the mysql table one by one until the deletion is complete.
Let me introduce myself first. The editor graduated from Jiaotong University in 2013. I worked in a small company and went to big factories such as Huawei and OPPO. I joined Ali in 2018, until now.I know that most junior and intermediate java engineers want to upgrade their skills, they often need to explore their own growth or sign up to study, but for training institutions, the tuition fee is nearly 10,000 yuan, which is really stressful.Self-learning that is not systematic is very inefficient and lengthy, and it is easy to hit the ceiling and the technology stops.Therefore, I collected a "full set of learning materials for java development" for everyone. The original intention is also very simple. I hope to help friends who want to learn by themselves but don't know where to start, and at the same time reduce everyone's burden.Add the business card below to get a full set of learning materials
边栏推荐
猜你喜欢

云数据库和本地数据库有什么区别?

MySQL database - DQL data query language

Linux download and install mysql5.7 version tutorial the most complete and detailed explanation

来了!东方甄选为龙江农产品直播带货

MindSpore:【模型训练】【mindinsight】timeline的时间和实际用时相差很远

win2003下FTP服务器如何搭建

MySQL六脉神剑,SQL通关大总结

The 17th "Revitalization Cup" National Youth Vocational Skills Competition - Computer Programmers (Cloud Computing Platform and Operation and Maintenance) Participation Review and Summary

部分分类网络性能对比
![[hbuilder] cannot run some projects, open the terminal and cannot enter commands](/img/fa/63f36683d090558f3fe5f582d86ca0.png)
[hbuilder] cannot run some projects, open the terminal and cannot enter commands
随机推荐
Range.CopyFromRecordset method (Excel)
VBA 连接Access数据库和Excle
第一次进入小程序判断
【MindSpore1.2.0-rc1产品】num_workers问题
MySQl数据库————DQL数据查询语言
【刷题篇】计算质数
MindSpore:ImageFolderDataset数据读取问题
MySQL性能优化(硬件,系统配置,表结构,SQL语句)
MySQL eight-part text recitation version
MySQL slow query optimization
Tensorflow2.0 confusion matrix does not match printing accuracy
How to install and use PostgreSQL 14.4
ImportError:attempted relative import with no known parent package
云数据库和本地数据库有什么区别?
【私人系列】日常PHP遇到的各种稀奇古怪的问题
MindSpore:【MindSpore1.1】Mindspore安装后验证出现cudaSetDevice failed错误
牛客网——华为题库(100~108)
Object和Map的区别
Cesium loads offline maps and offline terrain
The JDBC programming of the MySQL database