Portable SQL/Statements/Data retrieval/Simple SELECT

From Linuxnetworks
< Portable SQL‎ | Statements/Data retrieval
Revision as of 21:05, 17 May 2007 by Nose (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The SQL language uses SELECT statements for asking the database server to send results based on the conditions back to the client. Contrary to the data manipulation statements which were only extended slightly by the database vendors, the portability of SELECT statements becomes a nightmare very fast.

Simple SELECTs

The simplest but also very limited statement for fetching records from a single table is

SELECT column-list
FROM table

To be on the save side column-list should be either a comma-separated list of column names or an asterisk (*). The asterisk symbol frees you from the burden to list all columns you would like to access in your application. But be careful! If your table has many columns the performance drops significant because more values have to be passed to the client over the network and the wire is the bottleneck most of the time. The problem will get worse if the table contains columns with much data for the same reason. Moreover, additional problems may arise as soon as you begin to join another table so don't use the asterisk without thinking twice if it's worth the potential trouble!

This kind of SELECT statement is not very useful most of the time. It will send all records of that table over the network even if there are millions of rows in it. Using this, you are asking for trouble as soon as your application stores user generated content into this table. Maybe the highscore of a small game? What will happen if it gets popular by a link on a big website?