2011-01-19 159 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

相关问题