學(xué)習(xí)啦 > 學(xué)習(xí)英語 > 專業(yè)英語 > 計算機英語 > 數(shù)據(jù)庫update的用法

數(shù)據(jù)庫update的用法

時間: 長思709 分享

數(shù)據(jù)庫update的用法

  數(shù)據(jù)庫update的用法的用法你知道嗎?下面小編就跟你們詳細介紹下數(shù)據(jù)庫update的用法的用法,希望對你們有用。

  數(shù)據(jù)庫update的用法的用法如下:

  SQL語句中的更新語句update是最常用的語句之一,下面將為您介紹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=InnoDB 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中設(shè)置第二條記錄(bs為2)的password為'***'。

  update t_test t

  set t.password = '***'

  where t.bs = 2;

  2、set多個字段

  在表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;

  這個是按照標準語法寫的,在不同的數(shù)據(jù)庫系統(tǒng)中,update還有更多的寫法,但是標準寫法都是支持的。以上三個例子為了說明情況,每次都更新一行。在實際中,可以通過where語句約束來控制更新行數(shù)。

543109