How mysql transfers data from one table to another

Source: Internet
Author: User

Mysql transfers data from one table to another. Stored PROCEDURE: DELIMITER $ www.2cto.com USE 'ms' $ drop procedure if exists 'sendsmsprocs '$ create definer = 'root' @ 'localhost 'processed' sendSmsProcs '(numberArrayId CHAR (32 ), longSmsId CHAR (32) BEGIN/* CREATE a temporary table and place the data in the TEMPORARY group to be issued */create temporary table tmp_table (phonenumber CHAR (11) TYPE = HEAP; truncate table tmp_table; create unique index tmp_table_index ON tmp_table (phonenumber); www.2cto.com/* put INTO temporary group data */insert into tmp_table SELECT phoneNumber FROM smsallphone WHERE smsallphone. numberArrayId = numberArrayId; select count (*) FROM tmp_table;/* CREATE a temporary table to query the existing number in the large TABLE */create temporary table tmp_table2 (phonenumber CHAR (11 )) TYPE = HEAP; truncate table tmp_table2; create unique index tmp_table2_index ON tmp_table2 (phonenumber);/* put the existing user number in the temporary data to be sent TABLE */insert into tmp_table2 SELECT region FROM tmp_table, smssystem WHERE tmp_table.phonenumber = smssystem. phoneNumber; select count (*) FROM tmp_table2;/* DELETE existing data to be published */delete from tmp_table WHERE tmp_table.phonenumber IN (SELECT phonenumber FROM tmp_table2 ); insert into smssystem SELECT replace (uuid (), '-', ''), longSmsId, phonenumber, sysdate (), sysdate (), 0, 0 FROM tmp_table; END $ DELIMITER;

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.