2011-01-19 215 views
0

此SQL的最佳方式是什麼?什麼是此更新的最佳解決方案

A)

update tableName set 
FieldA = (if FieldA = 1301 then null else FieldA endif), 
FieldB = (if FieldB = 1301 then null else FieldB endif) 
where Id = 707; 

B)

update tableName set FieldA = null where Id= 707 and FieldA = 1301; 
update tableName set FieldB = null where Id= 707 and FieldB = 1301; 

在模型 「A」 我只有一個SQL的作品,並解決了這個問題,並且模型 「B」 我有兩個SQL,與「A」模型做同樣的事情,但更具可讀性。

什麼是最適合使用的模型?

回答

1

我假設A溶液是較好的,因爲:

1少邏輯IO - 更好的性能

2以下的程序代碼,錯誤更少

3易於支持和維護

4這個更新很可讀

+0

我想知道即使當FieldA <> 1301時,第一個選項A)也不能觸發更新觸發器。甚至更新IO。我的意思是,引擎是否知道'更新設置FieldA = FieldA`會成爲NOP? – pascal 2011-01-24 13:01:17

相關問題