A brief understanding of the three uses of standard SQL update statements

A brief understanding of the three uses of standard SQL update statements

1. Environment:

MySQL-5.0.41-win32

Windows XP Professional

2. Establish a test environment:

DROP TABLE IF EXISTS t_test; 
CREATE TABLE t_test ( 
bs bigint(20) NOT NULL auto_increment, 
username varchar(20) NOT NULL, 
password varchar(20) default NULL, 
remark varchar(200) default NULL, 
PRIMARY KEY (bs) 
)ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=gbk; 
INSERT INTO t_test VALUES (1,'lavasoft','123456',NULL); 
INSERT INTO t_test VALUES (2,'hello',NULL,NULL); 
INSERT INTO t_test VALUES (3,'haha',zz,tt);

3. Testing

1. Set a field

In the table t_test, set the password of the second record (bs=2) to '***'.

update t_test t
set t.password = '***'
where t.bs = 2;

2. Set multiple fields

In the table t_test, set the password of the first record (bs is 1) to '*' and remark to '*'.

update t_test t
set t.password = '*', t.remark = '*'
where t.bs = 1;

3. Set null value

In the table t_test, set the password and remark of the third record (bs is 3) to null and null respectively.

update t_test t
set t.password = null, t.remark = null
where t.bs = 3;

Conclusion

This is written according to the standard syntax. In different database systems, there are more ways to write update, but the standard syntax is supported. In order to illustrate the situation, the above three examples update one row each time. In practice, the number of updated rows can be controlled through where statement constraints.

You may also be interested in:
  • Will MySQL execute the update statement again if it has the same data as the original one?
  • SQL UPDATE update statement usage (single column and multiple columns)
  • Detailed explanation of MySQL database insert and update statements
  • Tutorial on using UPDATE and DELETE statements in MySQL
  • Example tutorial on using UPDATE statement in MySQL
  • Correct use of MySQL update statement

<<:  An example of how Vue implements four-level navigation and verification code

>>:  How to use Nginx to proxy multiple application sites in Docker

Recommend

element-ui Mark the coordinate points after uploading the picture

What is element-ui element-ui is a desktop compon...

How React Hooks Work

Table of contents 1. React Hooks vs. Pure Functio...

Detailed explanation of how Tomcat implements asynchronous Servlet

Preface Through my previous Tomcat series of arti...

Java uses Apache.POI to export HSSFWorkbook to Excel

Use HSSFWorkbook in Apache.POI to export to Excel...

Vue project implements left swipe delete function (complete code)

Achieve results The code is as follows html <t...

Example of implementing load balancing with Nginx+SpringBoot

Introduction to Load Balancing Before introducing...

Zabbix WEB monitoring implementation process diagram

Take zabbix's own WEB interface as an example...

Web page header optimization suggestions

Logo optimization: 1.The logo image should be as ...

Analysis of Context application scenarios in React

Context definition and purpose Context provides a...

MySQL 5.7.17 installation and configuration tutorial under Linux (Ubuntu)

Preface I have installed MySQL 5.6 before. Three ...

Full process record of Nginx reverse proxy configuration

1. Preparation Install Tomcat on Linux system, us...

Docker builds CMS on-demand system with player function

Table of contents text 1. Prepare the machine 2. ...

A brief discussion on the role of the docker --privileged=true parameter

Around version 0.6, privileged was introduced to ...

JavaScript implements the nine-grid mobile puzzle game

This article shares the specific code for JavaScr...