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, 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 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. Typically, queries are in this form:

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

For example, you might like to see information about your customers in the United States. To do so you would write:

 Select CompanyName, ContactName from Customers where Country ...

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