I seen some queries including table name with t suffix. like
select *
from MyTable t
or
select Col1, Col2, Col3
from MyTable t with (nolock)
where ....
I searched, but I was not able to understand what is the purpose of including the t after inserting table name.
NOLOCK
when you don't understand the implications and consequences of its use. – LarnuNOLOCK
meansread dirty and duplicate data while taking excessive locks and randomly throwing errors
. It doesn't meango fast
, it means the query has a serious performance problem that someone tried to cover up – Panagiotis KanavosI searched
aliases are fundamental SQL concepts, used in all databases. They're mentioned in all articles, tutorials and courses for the simple reason that nobody wants to write the full table or column names all the time. In many cases they're necessary, eg when you want to join a table to itself, or when a query uses multiple tables with one or more identical names – Panagiotis KanavosAS
some don't, it's more preference. It's not really that much shorter. What is way short isSELECT t1.Col1, T2.Col1
overSELECT Table1.Col1, Table2.Col2
. – LarnuNOLOCK
is essentially a tornado siren warning that the queries have performance or concurrency issues that were covered up. Quite often the coverup results in other, hard to diagnose errors. Beware, there are other dragons in that system – Panagiotis Kanavos