next up previous contents index
Next: Summary Up: SQL Aggregates Previous: Using HAVING

Query Tips

In Figures [*] and [*], the queries are spread over several lines. When a query has several clauses, such as FROM, WHERE, and GROUP BY, it is best to place each clause on a separate line. This convention makes queries easier to understand. Clear queries also use appropriate capitalization.

In a test database, mistakes do not create a problem. In a live production database, however, one incorrect query can cause great difficulty. It takes five seconds to issue an erroneous query, and sometimes five days to recover from it. Double-check your queries before executing them.  This consideration is especially important for UPDATE , DELETE , and INSERT  queries, because they modify the database. Also, before performing an UPDATE or DELETE, do a SELECT or SELECT COUNT(*) with the same WHERE clause. Make sure the SELECT result is reasonable before doing the UPDATE  or DELETE. 


Bruce Momjian
2001-05-09