Are these two statements equivalent?
UPDATE Table1 SET Field1=(
SELECT Field2 FROM Table2
WHERE Table1.ID=Table2.ID
)
FROM Table1
WHERE Field1 is null
UPDATE t SET Field1=(
SELECT Field2 FROM Table2
WHERE t.ID=Table2.ID
)
FROM Table1 t
WHERE Field1 is null
I’m trying to reduce the amount of aliasing.
I feel that adding an alias to a statement only adds another table name to keep track of mentally.
My concern is that in example 1, since I’m not using the alias, it will update the entire table1 instead of filtering on the WHERE Field1 is null.
What is the rule of thumb for when aliasing is required?
Yes, they’re equivalent, because aliasing won’t ever change the effect of a statement, only its readability or resolving ambiguity.
But I’d do this:
or this
Use aliasing to help readability. Personally I like using short aliases (1-3 chars) for each of my tables, always using the same aliases for the same tables wherever possible so over time readability improves.