Mysql updates certain fields of another table based on data from one table (sql statement)

Mysql updates certain fields of another table based on data from one table (sql statement)

The following code introduces MySQL to update some fields of another table based on the data of one table. The specific code is as follows:

DROP TABLE IF EXISTS T_U_TEMPLATE;
-- Template table CREATE TABLE T_U_TEMPLATE (
 ID INT NOT NULL AUTO_INCREMENT comment 'Template table ID',
 TEMPLATE_CODE VARCHAR(50) BINARY comment 'Template code',
 TEMPLATE_NAME VARCHAR(300) BINARY comment 'Template name',
 CREATE_TIME datetime DEFAULT NULL COMMENT 'Creation time',
 CREATE_BY varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'Creator' ,
 UPDATE_BY varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci COMMENT 'Updater' ,
 UPDATE_DATE datetime COMMENT 'Update time',
 constraint PK_U_TEMPLATE primary key (ID)
)DEFAULT CHARSET=utf8 comment 'Template table';
DROP TABLE IF EXISTS TEMPLATE_TEMP_CREATE;
-- Template temporary table CREATE TABLE TEMPLATE_TEMP_CREATE (
 ID INT NOT NULL AUTO_INCREMENT comment 'Template table ID',
 OBJECT_ID VARCHAR(50) BINARY comment 'Template code',
 OPERATER_NAME varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'Updater' ,
 CREATE_TIME datetime NOT NULL COMMENT 'Update time',
 constraint PK_U_TEMPLATE primary key (ID)
)DEFAULT CHARSET=utf8 comment 'Template temporary table';
-- Modify the creator's creation time to the T_U_TEMPLATE table UPDATE T_U_TEMPLATE a,TEMPLATE_TEMP_CREATE b SET a.CREATE_TIME=b.CREATE_TIME WHERE a.TEMPLATE_CODE = b.OBJECT_ID;
UPDATE T_U_TEMPLATE a,TEMPLATE_TEMP_CREATE b SET a.CREATE_BY=b.OPERATER_NAME WHERE a.TEMPLATE_CODE = b.OBJECT_ID;

Summarize

The above is what I introduced to you about Mysql updating certain fields of another table based on the data of one table. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • Getting Started with MySQL (IV) Inserting, Updating, and Deleting Data from a Table
  • MySQL data insertion optimization method concurrent_insert
  • MySQL data insertion efficiency comparison
  • Why is the disk space still occupied after deleting table data in MySQL?
  • Detailed explanation of the idea of ​​MySQL trigger detecting a statement in real time for backup and deletion
  • mysql data insert, update and delete details

<<:  Key knowledge summary of Vue development guide

>>:  Detailed steps for porting busybox to build a minimal root file system

Recommend

Example code for implementing background blur effect with CSS

Is it the effect below? If so, please continue re...

Mini Programs use Mini Program Cloud to implement WeChat payment functions

Table of contents 1. Open WeChat Pay 1.1 Affiliat...

About vue component switching, dynamic components, component caching

Table of contents 1. Component switching method M...

Will css loading cause blocking?

Maybe everyone knows that js execution will block...

MySQL database operations and data types

Table of contents 1. Database Operation 1.1 Displ...

10 skills that make front-end developers worth millions

The skills that front-end developers need to mast...

WeChat applet implements a simple calculator

WeChat applet's simple calculator is for your...

What is em? Introduction and conversion method of em and px

What is em? em refers to the font height, and the ...

CSS implements six adaptive two-column layout methods

HTML structure <body> <div class="w...

How to use Celery and Docker to handle periodic tasks in Django

As you build and scale your Django applications, ...

How to implement Linux automatic shutdown when the battery is low

Preface The electricity in my residence has been ...

The difference between ID and Name attributes of HTML elements

Today I am a little confused about <a href=&quo...

Things to note when migrating MySQL to 8.0 (summary)

Password Mode PDO::__construct(): The server requ...

CUDA8.0 and CUDA9.0 coexist under Ubuntu16.04

Preface Some of the earlier codes on Github may r...