当前位置:网站首页>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
- el-input 只能输入整数(包括正数、负数、0)或者只能输入整数(包括正数、负数、0)和小数
- Range.CopyFromRecordset 方法 (Excel)
- 已删除
- Alibaba Cloud Martial Arts Headline Event Sharing
- LeetCode每日一题(1717. Maximum Score From Removing Substrings)
- JS提升:Promise中reject与then之间的关系
- 【科普】无线电波怎样传送信息?
- The advanced version of the cattle brushing series (search for rotating sorted arrays, inversion of the specified range in the linked list)
- 启动前台Activity
猜你喜欢
随机推荐
MindSpore:【JupyterLab】查看数据时报错
055 c# print
Range.CopyFromRecordset 方法 (Excel)
MySQL夺命10问,你能坚持到第几问?
Correct pose of Vulkan open feature
The advanced version of the Niu Ke brushing series (team competition, sorting subsequences, inverting strings, deleting common characters, repairing pastures)
【Node实现数据加密】
Cesium loads offline maps and offline terrain
MySQL数据库————视图和索引
MySQL六脉神剑,SQL通关大总结
win2003下FTP服务器如何搭建
技术很牛逼,还需要“向上管理”吗?
Start background services across processes
来了!东方甄选为龙江农产品直播带货
MySQL six-pulse sword, SQL customs clearance summary
云数据库和本地数据库有什么区别?
MySQL数据库 ---MySQL表的增删改查(进阶)
Listen to the boot broadcast
The 17th "Revitalization Cup" National Youth Vocational Skills Competition - Computer Programmers (Cloud Computing Platform and Operation and Maintenance) Participation Review and Summary
Linux下最新版MySQL 8.0的下载与安装(详细步骤)









