Chapter 1: Foundations of Querying Flashcards
How SQL Server attempts to represent a relation?
With a table. A relation has a heading and a body. A heading is a set of attributes (a set of columns in SQL Server), each one of given type. An attribute is identified by a name and a type. A body is a set of tuples (a set of rows in SQL Server). Each attribute of a tuple correspond to an attribute of the heading.
What math areas are based SQL?
In set theory and predicate logic.
What is the difference between T-SQL and SQL?
SQL is a standard, while T-SQL is a dialect of SQL.
What are the properties of a relation model?
(1) A relation should be considered as a whole - don’t work with one row at a time.
(2) A relation should not have duplicates.
(3) A relation should have no relevance to the order.
(4) All attributes must have names.
(5) All attribute names must be unique.
Why are the terms “field” and “record” incorrect when referring to column and
row?
Because “field” and “record” describe physical things, whereas columns and rows are logical elements of a table.
Why is the term “NULL value” incorrect?
Because NULL isn’t a value; rather, it’s a mark for a missing value.
What are the main query clauses in the “keyed-in” order?
(1) SELECT (2) FROM (3) WHERE (4) GROUP BY (5) HAVING (6) ORDER BY
What are the main query clauses in logical query processing order?
- FROM
- ON
- OUTER
- WHERE
- GROUP BY
- CUBE | ROLLUP
- HAVING
- SELECT
- DISTINCT
10 ORDER BY - TOP
What is the difference between the WHERE and HAVING clauses?
The WHERE clause is evaluated before rows are grouped, and therefore is evaluated
per row. The HAVING clause is evaluated after rows are grouped, and therefore is evaluated per group.
Why are you not allowed to refer to a column alias defined by the SELECT
clause in the same SELECT clause?
Because all expressions that appear in the same logical query processing phase are evaluated conceptually at the same point in time.
What is the GROUP BY Clause?
Defines a group for each distinct combination of values from the input tables columns in the GROUP BY list. All expressions processed in subsequent phases must guarantee a single value per group. Column references must be in the GROUP BY list or they must be contained within an aggregate function like MAX or SUM.
What is the HAVING clause?
This phase is responsible for filtering data based on a predicate, but it is evaluated after the data has been grouped. “HAVING COUNT(*) > 1” means to filter groups where there are multiple detail rows.