Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In SQL, are tuple variables mainly used to save typing-effort?

Tags:

sql

tuples

In a statement like this:

SELECT CUSTOMER_NAME, T.LOAN_NUMBER, S.AMOUNT
FROM BORROWER AS T, LOAN AS S
WHERE T.LOAN_NUMBER = S.LOAN_NUMBER

So the tuple variables here are T and S?

like image 589
Caffeinated Avatar asked Feb 23 '23 18:02

Caffeinated


1 Answers

They are useful for saving typing, but there are other reasons to use them:

  • If you join a table to itself you must give it two different names otherwise referencing the table would be ambiguous.
  • It can be useful to give names to derived tables, and in some database systems it is required... even if you never refer to the name.

Regarding the name, "tuple" comes from the idea that a row is a tuple of values, e.g. (1, 'Fred', 1400). However I don't know why it is called a variable, because it cannot be modified afterwards. I don't think this is a particularly common term to describe this feature. The SQL Standards refer to them as "correlation names". Looking at the major databases, all of them use another term instead:

  • In the MySQL manual and PostgreSQL manual they are refered to as aliases rather than tuple variables.
  • The Oracle manual describes them as table aliases or correlation names.
  • The SQL Server manual also uses the term table alias.
like image 62
Mark Byers Avatar answered Apr 26 '23 03:04

Mark Byers