自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

關(guān)于Update在不同數(shù)據(jù)庫的使用

運維 數(shù)據(jù)庫運維
SQL語法難嗎?其實不難。但是也有忘記的可能,因此作者將它寫下來,以備不時之需。現(xiàn)在分享給大家,一起來看看吧。

1、單表更新多個字段

DB2:

  1. update t1 set (id, name)=('1','2'where name like 'kiss%'--正確運行  
  2. update t1 set id='1',name='2' where name like  'kiss%'--正確運行 

MSSQL:

  1. update t1 set (id, name)=('1','2'where name like 'kiss%'----報: '(' 附近有語法錯誤。  
  2. update t1 set id='1',name='2' where name like  'kiss%'--正確運行 

2、多表連合更新

DB2:

  1. update t1 set id=(select id from t2 where t2.name like  'kiss%'--正確運行  
  2. update t1 set (id,name)=(select id,name from t2 where t2.name like  'kiss%'--正確運行  
  3. update t1 a set id=b.id from t2 b where b.id='dkdkd'--sql遇到非法符號 

MSSQL:(update tablename 別名,這種寫法是不對的)

  1. update t1 set id=b.id, bid=b.bid from t2 b where b.bid='dkdkd' --正確運行  
  2. -----如果要用別名,則也要把t1放在from后面------  
  3. update a set a.id=b.id, a.bid=b.bid from t1 a, t2 b where a.id=b.id and b.bid='dkdkd' --正確運行(別名放在from后) 

綜上,更新多個字段,有兩種寫法,分別是

  1. update tname set (a1, a2...)=(select a1, a2...from...)--DB2寫法  
  2. --------------------華麗分割線----------  
  3. update tname set a1=b.a2, a2=b.a2...from b...   --mssql 寫法 

Oracle下面跟db2差不多,環(huán)境沒搭建好,就不測試了,要用的時候再參考以上兩種寫法.

簡單在mysql下測試,結(jié)果如下,mysql與mssql都支持 set a1=b.a2, a2=b.a2...from b. 的寫法

  1. mysql> update order2 set id=1,price=2 where ordernum='kdkdk' 
  2.     -> ;  
  3. Query OK, 0 rows affected (0.00 sec)  
  4. Rows matched: 0  Changed: 0  Warnings: 0  
  5.  
  6. mysql> update order2 set (id, price)=(1,2) where ordernum='dkdkd' 
  7.     -> ;  
  8. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that  
  9. corresponds to your MySQL server version for the right syntax to use near '(id,  
  10. price)=(1,2) where ordernum='dkdkd'at line 1 

原文鏈接: http://shoushou2001.iteye.com/blog/1110350

【編輯推薦】

  1. 客戶的一次疏忽,DBA的一次噩夢
  2. 單數(shù)據(jù)庫vs多數(shù)據(jù)庫,單實例vs多實例 效率測試
  3. 一個筆記告訴你,從Java存儲轉(zhuǎn)到SQL存儲的過程
  4. Oracle數(shù)據(jù)庫日常維護(hù)知識總結(jié)
責(zé)任編輯:艾婧 來源: Java place
相關(guān)推薦

2010-08-31 16:59:12

DB2UPDATE

2009-04-30 09:28:05

SynonymOpenquerySQL Server

2024-12-06 08:29:29

2011-07-18 16:56:12

Sqlite數(shù)據(jù)庫Update語句

2011-08-24 13:10:48

MongoDBUpdate

2011-05-18 10:36:21

數(shù)據(jù)庫數(shù)據(jù)導(dǎo)入

2011-08-04 13:07:59

數(shù)據(jù)庫查詢TOP子句

2017-05-25 10:23:13

數(shù)據(jù)a表b表

2019-12-26 17:25:22

數(shù)據(jù)庫設(shè)計技術(shù)

2011-08-23 15:16:54

OracleMySQL

2010-05-12 18:48:31

MySQL數(shù)據(jù)庫

2010-05-10 18:05:09

2018-08-24 13:58:13

數(shù)據(jù)庫MySQL備份

2011-08-04 15:55:25

SQL Server數(shù)

2024-08-09 08:28:14

品牌數(shù)據(jù)庫產(chǎn)品

2011-08-03 14:02:02

數(shù)據(jù)庫連接ACCESS

2013-05-21 10:06:11

數(shù)據(jù)庫查詢優(yōu)化

2017-10-18 19:12:24

數(shù)據(jù)庫Oracle安全管理

2010-08-18 17:45:36

DB2數(shù)據(jù)庫

2010-04-23 15:34:41

Oracle 數(shù)據(jù)庫
點贊
收藏

51CTO技術(shù)棧公眾號