SQL的update語句怎么寫
UPDATE 表名稱 SET 列名稱 = 新值 WHERE 列名稱 = 某值,update語句的寫法:
1、UPDATE table_name
2、SET column1=value1,column2=value2,。
3、WHERE column(1)=value(1),column(2)=value(2)。and column(n)=value(n);
4、UPDATE Person SET Address = 'Zhongshan 23', City = 'Nanjing',WHERE LastName = 'Wilson'
擴展資料
SQL的update語句寫法的特點
1、一體化:SQL集數據定義DDL、數據操縱DML和數據控制DCL于一體,可以完成數據庫中的全部工作。
2、使用方式靈活:它具有兩種使用方式,即可以直接以命令方式交互使用;也可以嵌入使用,嵌入到C、C++、FORTRAN、COBOL、JAVA等主語言中使用。
3、非過程化:只提操作要求,不必描述操作步驟,也不需要導航。使用時只需要告訴計算機“做什么”,而不需要告訴它“怎么做”。
4、語言簡潔,語法簡單,好學好用:在ANSI標準中,只包含了94個英文單詞,核心功能只用6個動詞,語法接近英語口語。
參考資料來源:搜狗百科—update (數據庫SQL語法用語)
sql數據庫更新語句
SQL語句中的更新語句update是最常用的語句之一,下面將介紹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=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中設置第二條記錄(bs為2)的password為'***'。
update t_test t
set *rd = '***'
where * = 2;
2、set多個字段
在表t_test中設置第一條記錄(bs為1)的password為'*'、remark為'*'。
update t_test t
set *rd = '*', * = '*'
where * = 1;
3、set null值
在表t_test中設置第三條記錄(bs為3)的password為null、remark為null。
update t_test t
set *rd = null, * = null
where * = 3;
這個是按照標準語法寫的,在不同的數據庫系統中,update還有更多的寫法,但是標準寫法都是支持的。以上三個例子為了說明情況,每次都更新一行。在實際中,可以通過where語句約束來控制更新行數。
oracle數據庫update語句
update兩表關聯的寫法包括字查詢
* t2 set parentid=(select ownerid from t1 where *=*);
2. update tb_client_win_lost_report a set *g_code_id=2
where game_code_id=70000
and exists
(select 'x' from (select *
from (select id,level_ from tb_admin_role connect by prior id=parent_id start with id =1) a,
(select lv_id from tb_rolling_plan where rolling_code_id = 2 and game_code_id=70000) b
where *_id=*) c where *_id=*)
and rolling_code_id=1
3. update (select rolling_code_id from tb_client_win_lost_report a,temp_role_id b
where *_id=*
and rolling_code_id=1) a set *g_code_id=2;
4. update tb_client_win_lost_report a set *g_code_id=2
where game_code_id=70000
and exists
(select 'x' from (select id from temp_role_id) c where *_id=*)
and rolling_code_id=1
and rownumcommit;
* 多個字段的寫法
update a set (c1,c2,c3) =(select b1,b2,b3 from b where。。) where 。。;
sql查詢 更新語句怎么寫
1、首先需要打開sql server 數據庫。
2、點擊新建查詢按鈕,進入sql 執行界面。
3、編寫sql 更新語句,update tablename set name='更新' ,點擊執行按鈕。
4、使用查詢語句,檢查是否更新成功,select * from tablename。
5、上面的語句是對數據庫進行批量更新,如果更新指定的信息可以在update 語句后面加上where語句update tablename set name='根據條件更新' where id=1 。
6、使用查詢語句,檢查是否更新成功,select * from tablename where id=1。
一個數據庫更新操作的SQL語句
update ClassSubject set AvgScore=*
from ClassSubject a,(select sum(AvgScore) as sas,ClassId,SubjectId from ItemValid group by ClassId,SubjectId) b
where *d=*d and *tId=*tId
如果不行的話就將查詢做一個臨時表
select sum(AvgScore) as sas,ClassId,SubjectId INTO #A from ItemValid group by ClassId,SubjectId
go
update ClassSubject set AvgScore=*
from ClassSubject a,#A b
where *d=*d and *tId=*tId
go
轉載請注明出處華閱文章網 » 數據庫更新數據的語句