Specifying tables: the from clause

The from clause is required in every select statement involving data from tables or views. Use it to list all the tables and views containing columns included in the select list and in the where clause. If the from clause includes more than one table or view, separate them with commas.

The maximum number of tables and views allowed in a query is 16. This includes tables listed in the from clause, base tables referenced by a view definition, any tables referenced in subqueries, a table being created with the into keyword, and any tables referenced as part of referential integrity constraints.

The from syntax looks like this:

select select_list 
     [from [[database.]owner.] {table_name |view_name}
                [holdlock | noholdlock] [shared]
         [, [[database.]owner.] {table_name | view_name}
                  [holdlock | noholdlock] [shared]]...] 

Table names can be between 1 and 30 bytes long. You can use a letter, @, #, or _ as the first character. The characters that follow can be digits, letters, or @, #, $, _, ¥, or £. Temporary table names must begin either with “#” (pound sign), if they are created outside tempdb, or with “tempdb..”. If you create a temporary table outside tempdb, its name must be less than 13 bytes, since Adaptive Server attaches an internal numeric suffix to the name to ensure that the name is unique. For more information, see Chapter 8, “Creating Databases and Tables.”

The full naming syntax for tables and views is always permitted in the from clause:

database.owner.table_name 
     database.owner.view_name 

However, the full naming syntax is necessary only if there is some confusion about the name.

You can give table names correlation names to save typing. Assign the correlation name in the from clause by giving the correlation name after the table name, like this:

select p.pub_id, p.pub_name 
from publishers p 

All other references to that table (for example, in a where clause) must also use the correlation name. Correlation names cannot begin with a numeral.