Specifications
SHOW GRANTS FOR user Shows the GRANT statements required to give
the user specified in user his current level
of privilege.
Getting Information About Columns with DESCRIBE
As an alternative to the SHOW COLUMNS statement, you can use the DESCRIBE statement, similar
to the DESCRIBE statement in Oracle (another RDBMS). The basic syntax for it is
DESCRIBE table [column];
This will give information about all the columns in the table or a specific column if column is
specified. You can use wildcards in the column name if you like.
Understanding How Queries Work with EXPLAIN
The EXPLAIN statement can be used in two ways. First, you can use
EXPLAIN table;
This gives very similar output to DESCRIBE table or SHOW COLUMNS FROM table.
The second and more interesting way you can use EXPLAIN allows you to see exactly how
MySQL evaluates a SELECT query. To use it this way, just put the word explain in front of a
SELECT statement.
You can use the EXPLAIN statement when you are trying to get a complex query to work and
clearly haven’t got it quite right, or when a query’s taking a lot longer to process than it
should. If you are writing a complex query, you can check this in advance by running the
EXPLAIN command before you actually run the query. With the output from this statement, you
can rework your SQL to optimize it if necessary. It’s also a handy learning tool.
For example, try running the following query on the Book-O-Rama database. It produces the
output shown in Figure 11.2.
explain
select customers.name
from customers, orders, order_items, books
where customers.customerid = orders.customerid
and orders.orderid = order_items.orderid
and order_items.isbn = books.isbn
and books.title like ‘%Java%’;
Advanced MySQL
C
HAPTER 11
11
ADVANCED
MY
SQL
257
TABLE 11.6 Continued
Variation Description
14 7842 CH11 3/6/01 3:35 PM Page 257