Mysql stored procedure: copy A column of Table A to Table B _ MySQL

Source: Internet
Author: User
Mysql stored procedure: copy A column of Table A to Table B to go to bitsCN.com

Mysql stored procedure: copy A column of Table A to Table B

This is a stored procedure used to copy the value of the avalue column in Table A to the bvalue column in Table B (assume that both Table A and Table B have the same column named id)

[SQL]

Create procedure copy_field ()

Begin

Declare tid int default 0;

Declare tvalue int default 0;

Declare B int default 0;

Declare cur cursor for select a. id, a. avalue from tableA as a join tableB as B where a. id = B. id;

Declare continue handler for not found set B = 1;

Open cur;

Set B = 0;

Repeat

FETCH cur INTO tid, tvalue;

Update tableB set bvalue = tvalue where id = tid;

Until B> 0

End repeat;

Close cur;

End

BitsCN.com

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.