簡單了解標(biāo)準(zhǔn)SQL的update語句三種用法
一、環(huán)境:
MySQL-5.0.41-win32
Windows XP professional
二、建立測試環(huán)境:
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一個(gè)字段
在表t_test中設(shè)置第二條記錄(bs為2)的password為'***'。
update t_test t set t.password = '***' where t.bs = 2;
2、set多個(gè)字段
在表t_test中設(shè)置第一條記錄(bs為1)的password為'*'、remark為'*'。
update t_test t set t.password = '*', t.remark = '*' where t.bs = 1;
3、set null值
在表t_test中設(shè)置第三條記錄(bs為3)的password為null、remark為null。
update t_test t set t.password = null, t.remark = null where t.bs = 3;
結(jié)語
這個(gè)是按照標(biāo)準(zhǔn)語法寫的,在不同的數(shù)據(jù)庫系統(tǒng)中,update還有更多的寫法,但是標(biāo)準(zhǔn)寫法都是支持的。以上三個(gè)例子為了說明情況,每次都更新一行。在實(shí)際中,可以通過where語句約束來控制更新行數(shù)。
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。