|
SQL is the language for accessing data in relational
databases.
Our SQL programming course has a primary emphasis on solving problems using SQL
("thinking in SQL"), a secondary emphasis on integrating SQL into a vendor's SQL
extensions to do what's considered to be traditional programming (in this case, SQL
Server's T-SQL dialect), and almost no emphasis on the data definition language (DDL -
create, drop, alter table) that is typically considered to be a database administration
function, not an application developer's function. The main goal of the course is to
provide the student with the ability to use SQL to solve non-trivial business problems.
Our focus is to teach the syntax early, and then spend time solving business
problems with SQL. In order to tackle the primary objective (thinking in SQL), we cover:
- syntax of the basic constructs (select, aggregate functions (sum, count, etc.),
builtin functions (convert, substring, etc.)
- various datatypes, various types of expressions (value expressions, logical
expressions)
- tri-valued logic and NULL
- filtering data with DISTINCT and WHERE
- joining tables (2-table and multi-table joins, inner and outer joins)
- sub-selects (selects as where-criteria, selects as members of the select list)
aggregates supported by grouping
- advanced queries, such as cross-tabulations using select
We use the knowledge developed in the first part of the class to tackle
"hard queries" -- business-based questions solved with select. For example:
- "write a query that shows all pairs of employees who have the exact same
skills", or
- "write a query to show employee last name, first name, school name, the
count of employees who went to the same school, and the count of classmates who are both
younger and making more money than this employee"
To handle some of the "hard queries", we use the T-SQL extensions of
SQL Server. These allow a person to write programs that contain standard if-then-else and
looping logic, combined with SQL. An additional programmatic SQL construct, the
"cursor", is also introduced and used. We explore the creation and use of
temporary tables, and write small programs to solve problems that can't be solved with a
single SQL statement.
|