Friday, 5 August 2011

Specifying Absolute Databases and Tables

An additional piece of notation you should be aware of at this point allows you to absolutely specify which database and table we are talking about. For example, we can refer to the name column in the employee table as employee.name. For example:

select employee.name
from employee;

This should give something similar to the following result:

+---------------+
| name |
+---------------+
| Ajay Patel |
| Nora Edwards |
| Candy Burnett |
| Ben Smith |
+---------------+
4 rows in set (0.41 sec)

Similarly, we can absolutely specify which table in which database we are talking about, for example:

select name
from employee.employee;

(This should give the same result as the preceding query.)

Here, we are making explicit reference to the employee table within the employee database. The notation here is database.table.

If desired, we can specify which database and table a column belongs to. The same example could be written using database.table.column syntax like this:

select employee.employee.name
from employee;

For these simple queries, this syntax is not very useful, but as we move on to more complex queries, this allows us to be unambiguous about what information we are looking for.

No comments:

Post a Comment