Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to copy the table structure and data to a new table by mysql

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "how to copy the table structure and data to the new table by mysql". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to copy the table structure and data to the new table by mysql.

1. Copy the table structure and data to the new table

CREATE TABLE new table SELECT * FROM old table

This method copies everything in the oldtable, and of course we can delete it with delete from newtable;.

However, one of the worst aspects of this approach is that the new table does not have the primary key, Extra (auto_increment) and other properties of the old table. You need to add it with "alter" yourself, and it's easy to make a mistake. 2. Only copy the table structure to the new table

CREATE TABLE new table SELECT * FROM old table WHERE 1 # 2

Or CREATE TABLE new table LIKE old table 3, copy the data from the old table to the new table (assuming the two tables have the same structure)

INSERT INTO new table SELECT * FROM old table 4, copy the data from the old table to the new table (assuming the structure of the two tables is different)

INSERT INTO new table (field 1, field 2.) SELECT field 1, field 2. FROM Old Table 5, Table 1 structure can be copied to Table 2

SELECT * INTO Table 2 FROM Table 1 WHERE 1 # 2 6, you can copy all the contents of Table 1 to Table 2

SELECT * INTO Table 2 FROM Table 1 7, show create table Old Table

This lists the creation commands for the old table. We just need to copy the command and change the name of table to create an identical table.

At this point, I believe you have a deeper understanding of "mysql how to copy the table structure and data to the new table". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report