SQL statement used to copy data of two fields in a database table

Source: Internet
Author: User

SQL statement used to copy data of two fields in a database table

Today, I want to add a new field to the table, but want to be the same as the value of another field in the Table. Because I want to implement the data through SQL statements, the following sentence is really useful after testing.
 

Copy codeThe Code is as follows:
Update jb51_temp set B =



Jb51_temp indicates that A has a value field, and B is A newly added field. Remember to put the null value table in front of it. If set a = B, all your values are empty, which makes it troublesome, we recommend that you back up the database before the operation.


How to copy a field value to another field

For example, there are two fields A and B. The value of field A is "me" and the value of field B is "us". How to copy the value of field B to field A using the update statement, and the combination with A should be placed behind the original content. after the update, field A should be "we" and field B will not change.

Copy codeThe Code is as follows:


Update table set A = A + B

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.