SQL

The language of choice for querying and manipulating databases is Structured Query Language, often referred to as SQL. SQL is often pronounced “sequel.” SQL is a declarative language, as opposed to a procedural language, and it can take awhile to get used to working with a declarative language if you are used to languages such as Visual Basic and C#.

Most programmers tend to think in terms of a sequence of steps: “Find me all the orders, then get the customer’s ID, then use that ID to look up that customer’s records in Customer, then get me the email address.” In a declarative language, such as SQL, you declare the entire query and the query engine returns a set of results. You are not thinking about a set of steps; rather, you are thinking about designing and “shaping” a set of data. Your goal is to make a single declaration that will return the right records. You do that by creating temporary “wide” tables that include all the fields you need and then filtering for only those records you want: “Widen the SalesOrderHeader table with the Customer table, joining the two on the CustomerID, then filter for only those that meet my criteria.”

The heart of SQL is the query. A query is a statement that returns a set of records from the database. Typically, queries are in this form:

Select column,column,column from table where column = value

For example, you might like to see information about the customers served by Janet. To do so you would write:

Select FirstName, LastName, CompanyName ...

Get Programming ASP.NET 3.5, 4th Edition 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.