In SQL, what is the letter after the table name in select select?

AT

SELECT a.NAME, a.NUMBER, a.STRING, a.RDB$DB_KEY FROM ADMIN a 

what is it worth?

Thank.

+2
sql
Jun 15 '09 at 15:48
source share
9 answers

a is an alias for the ADMIN table

Alias ​​SQL

+24
Jun 15 '09 at 15:49
source share

An alias for the ADMIN table. This is not needed here because there is only one table in your query.

If you have several tables, and some of them are the same, you need to distinguish between them. One way is to write the table name before the column name. For example.

 Select ADMIN.Name, person.name from ADMIN, person where person.id = admin.id 

To make this shorter, add aliases for table names.

 select a.Name, p.Name from ADMIN a, person p where person.id = admin.id 
+2
Jun 15 '09 at 15:54
source share

a is what is called a table alias. In the query part, which says:

 FROM ADMIN a 

By placing "a" after the table name, you created an alias that can now be used instead of the table name. Without an alias, you will need to use the fully qualified table name to fully qualify the column names to which you refer in the query.

Without a table alias, your query would look like this:

 SELECT ADMIN.NAME, ADMIN.NUMBER, ADMIN.STRING, ADMIN.RDB$DB_KEY FROM ADMIN 

Although, since you only select columns from a single table, the table name (or alias) is actually not needed at all in this example.

+1
Jun 15 '09 at 15:51
source share

A is an alias for the table.

You can change a to any valid identifier, it does not depend on the underlying scheme. It is usually used to distinguish fields from different tables, which allows you to specify the full name of the table each time (makes it easier to read SQL using a short alias).

In fact, this is not required in the example you gave,

 SELECT NAME, NUMBER, STRING, RDB$DB_KEY FROM AMDIN 

should work just as well

+1
Jun 15 '09 at 15:51
source share

The query uses similar, so you do not need to write ADMIN.NAME, ADMIN.NUMBER, etc. etc. If you have fifteen fields on your table and your table has a name such as VPCPDEEE, it becomes very tedious to print the same table name again and again.

+1
Jun 15 '09 at 15:51
source share

The basic concept is a “range variable”.

Chris Date and Hugh Darwen believe that the term “nickname” and the term “Standard SQL terms” are “inappropriate” and “seriously [distort] the true state of things.”

Hugh Darwen, "SQL: A Comparative Study" :

You may have learned a different term for a range variable, which was used by Codd in its earlier documents, but was not adopted by the SQL standard until 2003. some SQL texts are called an alias, but this does not fit at all, really, because it means that this is the name of the table and therefore designates the table, not the row. The SQL standard uses an equally inappropriate term correlation name (it does not mean correlation, whatever it is), but only for the case when the name is explicit (through AS in the example), and not for the case when the simple table name is doubled as the name of a range variable . In SQL: 2003, a more general case was adopted as a convenient, uniform term to cover.

CJ Date, "SQL and relational theory: how to write accurate SQL code" :

a range variable in a relational model is a variable that has “ranges” above a set of rows in some table (or a set of tuples in some relations, to be more precise). In SQL, such variables are defined by AS specifications in the context of either FROM or JOIN , as in the following example:

 SELECT SX.SNO FROM S AS SX WHERE SX.STATUS > 15 

SX Here is the range variable, which is located in table S ; in other words, its valid values ​​are rows of table S You can think of a SELECT expression generally evaluated as follows. First, the range variable takes one of its allowed values, for example, a string for the provider SNO = 'S1' . Is the status value in this row greater than 15? If so, the result will be the vendor number 'S1' . Then the range variable goes to another row of table S , say, for provider SNO = 'S2' ; again, if the status value on this line exceeds 15, then the corresponding vendor number is displayed in the result. And so on

SQL requires that SELECT always formulated in terms of range variables; if such variables are absent explicitly indicated, it assumes the existence of implicit ones with the same names as the corresponding tables

Caution: Many SQL texts refer to range variable names (or correlation names) as aliases and describe them as if they were just alternate names for tables they vary. But this characteristic seriously distorts the true state of affairs - indeed, it gives out a serious lack of understanding of what is actually happening, and this account.




Interestingly, LINQ correctly recognizes range variables, for example.

enter image description here

+1
Jun 16 '09 at 9:12
source share

A - abbreviation (term: alias) for the ADMIN table

0
Jun 15 '09 at 15:50
source share

a = ADMIN

Equivalent:

 SELECT ADMIN.NAME, ADMIN.NUMBER, ADMIN.STRING, ADMIN.RDB$DB_KEY FROM ADMIN 
0
Jun 15 '09 at 15:53
source share

And used as an alias for the ADMIN table.

When to use an alias correctly and what form the alias should execute can raise some strong opinions from sql authors.

Here are some questions regarding stackoverflow on this subject.

When to use an SQL table alias

Are SQL Table Aliases Good or Bad?

0
Jun 16 '09 at 7:09
source share



All Articles