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 a while to get used to working with a declarative language if you are used to languages like VB or C#.

Most programmers tend to think in terms of a sequence of steps: “Find me all the bugs, then get the reporter’s ID, then use that ID to look up that user’s records in People, then get me the email address.” In a declarative language, 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 Bugs table with the People table, joining the two on the PersonID, 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. For example, you might like to see all of the BugIDs and Bug Descriptions in the Bugs table whose status is Open. To do so you would write:

Select BugID, BugDescription from Bugs where status = 'open'

SQL is capable of much more powerful queries. For example, suppose the Quality Assurance manager ...

Get Programming ASP.NET, Second 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.