Copy all data in a field of a table to another table.

Source: Internet
Author: User

Project requirements: the dream is hacked, and it will not be able to fix the dream vulnerabilities. I decided to change to a self-developed background! The problem is that all the data in the dream articles should be taken out and imported to the new background.

Because the structure of the existing data table in the background is completely different from that of the dream-Woven table. In addition, it is used to save the article. dede_addonarticle and dede_archives are two tables. Now we want to copy the data of useful fields in two tables to one field in a new table.

Step 1: synchronize their primary keys. The primary key of dede_addonarticle is aid, and the primary key of dede_archives is ID.

1. A table with a written structure and no data (new_table) is what we want to import data to this table

2. The primary key field in the blank table is ID. Because it is blank, you must first Insert the same primary key as dede_addonarticle and dede_arives.

This step is performed in the same database. If you want to perform cross-Database Operations, I have not studied it either. (import the tables of another database to this database for processing, after export, import the data to another database)

Use SQL statements

Insert into new_table (ID) select aid from dede_addonarticle (because the primary key of dede_addonarticle is aid)

In this way, the primary key can be synchronized.

Step 2: Synchronize other data

Update new_table set new_table.seo_title = (select dede_addonarticle.seo_title from dede_addonarticle where new_table.id = dede_addonarticle.aid)

This statement is used to synchronize other data. For example, the title label content in the head label is synchronized.

Note: to copy the title field of Table A to table B, the field name of Table B is not required. It can be any field name. In the preceding example, seo_title is the same name. Do not use the correct Sn.

Step 3: export the sorted data table and re-import it to the new database. In this way, the data is copied by field.

 

This practice is relatively simple. Of course, it is also a problem if you have never encountered it, So record it here. If you have a better method, please leave a message to me and thank you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.