|
标准SQL的update语句三种用法
一、环境:
MySQL-5.0.41-win32
Windows XP professional
二、建立测试环境:
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);
三、测试
1、set一个字段
在表t_test中设置第二条记录(bs为2)的password为'***'。
update t_test t
set t.password = '***'
where t.bs = 2;
2、set多个字段
在表t_test中设置第一条记录(bs为1)的password为'*'、remark为'*'。
update t_test t
set t.password = '*', t.remark = '*'
where t.bs = 1;
3、set null值
在表t_test中设置第三条记录(bs为3)的password为null、remark为null。
update t_test t
set t.password = null, t.remark = null
where t.bs = 3;
这个是按照标准语法写的,在不同的数据库系统中,update还有更多的写法,但是标准写法都是支持的。以上三个例子为了说明情况,每次都更新一行。在实际中,可以通过where语句约束来控制更新行数。
----------------------------
原文链接:https://blog.51cto.com/lavasoft/27692
程序猿的技术大观园:www.javathinker.net
[这个贴子最后由 flybird 在 2020-03-13 11:23:38 重新编辑]
|
网站系统异常
系统异常信息 |
Request URL:
http://www.javathinker.net/WEB-INF/lybbs/jsp/topic.jsp?postID=2793&pages=7
java.lang.NullPointerException
如果你不知道错误发生的原因,请把上面完整的信息提交给本站管理人员。
|
|