Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Update from inner SQL
Message
 
 
À
01/03/2011 18:21:54
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Web
Divers
Thread ID:
01502274
Message ID:
01502280
Vues:
27
>>I suggest to keep using an alias, but you're right, both syntaxes work in SQL Server and it's a bit confusing. IMHO, using an alias is consistent.
>>
>>BTW, many developers (say, MVP Hugo Kornelis) object using this syntax at all. Brad Schulz even has a blog 'Dear From Clause' on this exact topic.
>>-------------------------------------------------------
>>Dear FROM Clause,
>>
>>I know that Valentine’s Day is less than a week away, but I felt it was important to write you this letter… I had to put my feelings down on paper. I don’t know quite how to tell you this, but… well… our relationship cannot continue.
>>------------------------------------------------------------------------------------------------------------------------
>>
>>http://bradsruminations.blogspot.com/2010/02/dear-from-clause.html
>
>It is quite a blog of course. It is very interesting. So, basically, the best practice is to use an alias when we move out of the inner SQL, such as in my example. I also use alias when doing those very complex SQL in order to ease the readability and understanding of it. But, we've been trying to make something work since an hour and I found out that this syntax was not supported on the other backend. So, the question was, "Will this provide the same result?". It turned out to be the case. But, I have to say, I do not feel comfortable using the same table in the UPDATE clause than from the inner SQL. It is kind of scary. I mean, will this, once in while, provide a massive unwanted update on records we should not update?

It may.

I now prefer using this syntax:
;with cteToUpdate (select goes here)

select * from cteToUpdate -- if this works OK, then comment it

update cteToUpdate set ...
This is SQL Server proprietary code.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform