An Introduction to Structured Query Language SQL

It's impossible to get very far into a discussion of data access without running into SQL, the querying language used to communicate with all databases commonly in use today. SQL is a standards-based language that has as many variations as there are databases. This chapter uses constructs compliant with the latest SQL standard, SQL-92, wherever possible.

There are four fundamental operations supported by SQL:

□ SELECT—Used to retrieve data from a data source

□ INSERT—Used to add new records to a data source

□ UPDATE—Used to modify existing records in a data source

□ DELETE—Used to remove records from a data source

The terms record and field are commonly used when describing data. The data sources you'll be concerned with in this chapter can all be thought of as being stored in a two-dimensional grid. A record represents a single row in that grid. A field represents a column in the grid. The intersection of a record and a field is a specific value. A resultset is the term used to describe the set of data returned by a SQL SELECT statement.

You will notice that SQL keywords such as SELECT and UPDATE are shown in uppercase. This is considered good SQL programming practice. When viewing complex SQL statements, having SQL keywords in uppercase makes it significantly easier to distinguish between those keywords and their operands. The subsections of a SQL statement are called clauses. In all SQL statements, some clauses are required and others are optional. When describing the syntax of SQL statements, optional clauses and keywords will be surrounded by square brackets.

Use the Customers table from Microsoft's Northwind sample database, as shown in Figure 20-1, to illustrate the SQL syntax examples. Northwind must be installed with Access 2007 in order to follow many of the examples in this chapter.

_| tustomers X

ID^ Company- First Name - LastName

B lICompanyA [Anna [Bedecs

+ 2 Company B Antonio Gratacos Solsona

_ffl 3 Company C Thomas_Axen_

_ffl 5 Company E Martin_O'Donnell_

+ B Company F Francisco Pérez-Olaeta

_ffl 7 Company G Ming-Yang Xie_

+ 8 Company H Eiizabeth Andersen

_ffl 9 Company I Sven_Mortensen_

+ 10 Company J Roland Wacker ^

Record: n 1 of 29 > M K | ^ rI■:■ Filter | Search |

Figure 20-1

0 0

Post a comment