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

后端 未结 9 1035
时光取名叫无心
时光取名叫无心 2020-12-19 11:28

In

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

what does a stand for?

Thanks.

相关标签:
9条回答
  • 2020-12-19 11:30

    A is an alias for the table.

    You can change a to any valid identifier, it isn't dependant on the underlying schema. Usually it's used to differentiate fields from different tables, saves you typeing the full table name each time (makes the SQL easier to read with a short alias).

    It isn't actually required in the sample you gave,

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

    should work just as well

    0 讨论(0)
  • 2020-12-19 11:30

    The query is using a like that just so that you don't have to write ADMIN.NAME, ADMIN.NUMBER, etc etc. If you have fifteen fields on your table and your table has a name like VPCPDEEE it gets very tiresome to type the same table name over and over.

    0 讨论(0)
  • 2020-12-19 11:30

    a is what is called a table alias. In the part of the query that says:

    FROM ADMIN a
    

    By placing "a" after the table name, you have created an alias that can now be used in place of the table name. Without the alias, you would need to use the table's full name in order to fully-qualify the column name(s) that you are referring to in the query.

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

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

    Although since you are only selecting columns from a single table, the table name (or alias) actually isn't needed at all in this example.

    0 讨论(0)
  • 2020-12-19 11:38

    A is a shorthand notation (term: alias) for the table ADMIN

    0 讨论(0)
  • 2020-12-19 11:42

    a is an alias for the table ADMIN

    SQL Alias

    0 讨论(0)
  • 2020-12-19 11:44

    The a is used as an alias for the ADMIN table.

    When it is correct to use an alias, and of what form that alias should take can raise some strong opinions from writers of sql.

    Heres a couple of stackoverflow questions on the subject.

    When to use SQL Table Alias

    SQL Table Aliases - Good or Bad?

    0 讨论(0)
提交回复
热议问题