14.3. Using SQL
The Structured Query Language was developed in the early 1970s by Donald Chamberlin and Ray Boyce of IBM. It was designed to be a universal database language that could create, manage, and maintain relational databases. Entire books have been written on various SQL topics, so I cannot give it full coverage here. Rather, I will concentrate on a useful subset of SQL that you can use in your programs. Once you get comfortable with the basics, there are plenty of online sources that you can use to expand your SQL prowess.
14.3.1. The SELECT Statement
Perhaps the most used part of SQL is the query features that enable you to retrieve specific subsets of data from a database. Most queries are initiated with the SELECT statement. Its syntax is
SELECT fieldList FROM tablename
In this case, fieldList is a comma-separated list of the fields that you wish to retrieve from the database. For example, suppose you want to retrieve the first and last names from the phone book database using fields that are similar to those used in Chapter 13. Suppose the table that holds the relevant information is the Friends table. The SQL command would be written like this:
SELECT firstName,lastName FROM Friends
(It is a common practice to use uppercase letters for the SQL keywords, like SELECT and FROM in the preceding statement. This is not a requirement, but simply a convention most programmers use.) The sample SELECT statement generates a dataset that contains the first and last names ...
Get Beginning C# 3.0 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.