SQL statement UPDATE

Source: Internet
Author: User

Update is one of the most common SQL statements. The following describes three usage methods of update statements for your reference.

I. 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 = InnoDB AUTO_INCREMENT = 4 default charset = gbk;
 
 
Insert into t_test VALUES (1, 'lavasosft ', '123', NULL );
Insert into t_test VALUES (2, 'Hello', NULL, NULL );
Insert into t_test VALUES (3, 'hahaha', zz, tt );
 
Iii. Test
 
1. set a field
Set the password of the second record bs to 2 in the t_test table '***'.
Update t_test t
Set t. password = '***'
Where t. bs = 2;
 
2. set Multiple Fields
In the t_test table, set the password of the first record bs to 1) to '*' and remark '*'.
Update t_test t
Set t. password = '*', t. remark = '*'
Where t. bs = 1;
 
3. set null Value
In the t_test table, set the password of the third record bs to 3) to null, and the remark to null.
Update t_test t
Set t. password = null, t. remark = null
Where t. bs = 3;
 
This is written according to the standard syntax. In different database systems, there are more writing methods for update, but standard writing is supported. In the preceding three examples, a row is updated every time to illustrate the situation. In practice, you can use the where statement constraints to control the number of updated rows.
 

N + 1 select statement query in SQL

Introduction to select into and insert into select statements in SQL

How to resolve the in range parameter of a select statement in SQL Server

Use the conditional logic of SELECT statements in SQL

Nested SELECT statements in SQL statements

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.