看板 Database 關於我們 聯絡資訊
※ 引述《daphnekang (戴芬妮)》之銘言: : 不好意思..最近接了一個系統..看到裡面的SQL 有個比較奇怪的設計方式 : SQL中要update的欄位, 竟使用在where條件值中 : UPDATE table1 SET flag ='B' : WHERE flag ='A' AND currentDate = '20130724' : 目前運行的資料庫為 MS SQL 2000, 但之後會升到 2008 : 想請問各位DBA的專家.. : 這樣的寫法, MS SQL 底層會將where條件的資料鎖定, 再做update嗎? : 還是會有怎樣運作方式? : 個人感覺這種是很危險的寫法.. 不會危險,這是 RDBMS 很常見的操作,而且背後都有很成熟的理論在撐。 : 請幫忙解惑..謝謝 SQL Server also provides the optimistic concurrency control mechanism, which is similar to the multiversion concurrency control used in other databases. 這段出自 https://en.wikipedia.org/wiki/Microsoft_SQL_Server 這裡。 A snapshot transaction always uses optimistic concurrency control, withholding any locks that would prevent other transactions from updating rows. 這段出自 http://msdn.microsoft.com/en-us/library/tcbchxcb.aspx 這裡。 MyISAM (MySQL) 用的是 table lock 解決,是很簡單的方式。InnoDB 與 Oracle 用的是 MVCC,是目前最常見到的 RDBMS transaction 架構。而 Microsoft SQL Server 用的是 OCC 架構,也是很成熟的架構。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 112.121.80.241