当前位置:网站首页>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
边栏推荐
- [PyTorchVideo Tutorial 01] Quickly implement video action recognition
- Install Mysql5.7 under Linux, super detailed and complete tutorial, and cloud mysql connection
- MindSpore:对image作normalize的目的是什么?
- Day31 LeetCode
- 阿里云武林头条活动分享
- VBA batch import Excel data into Access database
- 谷歌AlphaFold近日宣称预测出地球上几乎所有蛋白质结构
- MySQL sub-database sub-table
- How to install and use PostgreSQL 14.4
- Linux download and install mysql5.7 version tutorial the most complete and detailed explanation
猜你喜欢

VS Code connects to SQL Server

2种手绘风格效果比较,你更喜欢哪一种呢?

MySQL数据库 ---MySQL表的增删改查(进阶)

ELK日志分析系统

VBA batch import Excel data into Access database

Golang logging library zerolog use record
![[PyTorchVideo Tutorial 01] Quickly implement video action recognition](/img/1a/696c5722bb94fabd688a8714ae2e8c.png)
[PyTorchVideo Tutorial 01] Quickly implement video action recognition

MySQL数据库————视图和索引

PostgreSQL 14.4如何安装使用

coming!Dongfang Selection brings goods to the live broadcast of Longjiang agricultural products
随机推荐
MindSpore:【语音识别】DFCNN网络训练loss不收敛
Encapsulates a console file selector based on inquirer
【hbuilder】运行不了部分项目 , 打开终端 无法输入指令
MindSpore:【resnet_thor模型】尝试运行resnet_thor时报Could not convert to
Range.CopyFromRecordset 方法 (Excel)
Linux下安装MySQL教程
Database Tuning - Database Tuning
LeetCode 0952. Calculate Maximum Component Size by Common Factor: Mapping / Union Search
Linux下载安装mysql5.7版本教程最全详解
MindSpore:【MindSpore1.1】Mindspore安装后验证出现cudaSetDevice failed错误
M3SDA:用于多源域自适应的矩匹配
Scala学习:类和对象
阿里云武林头条活动分享
NXP IMX8QXP更换DDR型号操作流程
HCIP --- 企业网的三层架构
【私人系列】日常PHP遇到的各种稀奇古怪的问题
Object和Map的区别
2种手绘风格效果比较,你更喜欢哪一种呢?
redis
牛客刷题系列之进阶版(组队竞赛,排序子序列,倒置字符串, 删除公共字符,修理牧场)