Three principal uses standard SQL update statement

Three principal uses standard SQL update statement
First, the environment:
MySQL-5.0.41-win32
Windows XP Professional
Second, create a test environment:
DROP TABLE IF EXISTS t_test;
The 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);
Third, the test
1, set a field
The second record (bs) in the table t_test set password ‘***’.
update t_test t
set t.password = ‘***’
where t.bs = 2;
2, set multiple fields
The first record (bs) in the table t_test set password for ‘*’ remark as ‘*’.
update t_test t
set t.password = ‘*’, t.remark = ‘*’
where t.bs = 1;
3, set a null value
The third record (bs) in the table t_test set password is null, remark to null.
update t_test t
set t.password = null, t.remark = null
where t.bs = 3;
This is in accordance with the standard syntax to write in a different database system, update wording, but the standard wording are supported. The above three examples to explain the situation, updated every time a row. In practice, by the where clause constraints to control the number of updated rows.

Posted by databasesql