Difference between revisions of "Portable SQL/Statements/Data retrieval/Simple SELECT"

From Linuxnetworks
Jump to: navigation, search
(simplest select)
 
Line 3: Line 3:
 
== Simple SELECTs ==
 
== Simple SELECTs ==
  
The simplest but also very limited statement for fetching records from a single table is
+
The simplest SELECT for fetching records from a single table which is supported by all database engines but also is of very limited use is
  
 
  SELECT ''column-list''
 
  SELECT ''column-list''

Revision as of 21:08, 17 May 2007

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 SELECT for fetching records from a single table which is supported by all database engines but also is of very limited use 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?