OVH Cloud OVH Cloud

le plus rapide ?

1 réponse
Avatar
Christophe
Quelle est la methode la plus rapide ?

** Methode 1
update matable set C1 = 1 where SEMSOR = 0 and C1 <> 1
update matable set C1 = 0 where SEMSOR <> 0 and C1 <> 0

** Methode 2
update matable set C1 =
case
when SEMSOR = 0 and C1 <> 1 then 1
when SEMSOR <> 0 and C1 <> 0 then 0
end





C1 = tinyint
SEMSOR = INT
Table matable contient ~90000 lignes et 133 champs

1 réponse

Avatar
SQLpro [MVP]
Christophe a écrit :
Quelle est la methode la plus rapide ?

** Methode 1
update matable set C1 = 1 where SEMSOR = 0 and C1 <> 1
update matable set C1 = 0 where SEMSOR <> 0 and C1 <> 0

** Methode 2
update matable set C1 > case
when SEMSOR = 0 and C1 <> 1 then 1
when SEMSOR <> 0 and C1 <> 0 then 0
end





C1 = tinyint
SEMSOR = INT
Table matable contient ~90000 lignes et 133 champs




en principe le 2


pour comparer les temps d'exec;

SET STATISTICS TIME ON

update matable set C1 = 1 where SEMSOR = 0 and C1 <> 1
update matable set C1 = 0 where SEMSOR <> 0 and C1 <> 0

update matable set C1 case
when SEMSOR = 0 and C1 <> 1 then 1
when SEMSOR <> 0 and C1 <> 0 then 0
end

SET STATISTICS TIME OFF

A +



--
Frédéric BROUARD, MVP SQL Server, expert bases de données et langage SQL
Le site sur le langage SQL et les SGBDR : http://sqlpro.developpez.com
Audit, conseil, expertise, formation, modélisation, tuning, optimisation
********************* http://www.datasapiens.com ***********************