Chapter 3: Filtering and Sorting Data Flashcards
What is a two-valued logic?
When a predicate return as response “TRUE” or “FALSE”.
What is a three-valued logic?
When a predicate returns as response “TRUE”, “FALSE” or “UNKNOWN”. It returns “UNKNOWN” when one of operands, or may both, is NULL.
NULL = NULL ?
Returns “UNKNOWN”.
What is a Search Argument (SARG)?
When the predicate is in the form “column operator value” or “value operator column”. Using the predicate in this way, SQL Server can use indexes.
Why we can’t apply a function to the filtered column?
Because it doesn’t allow SQL Server to use indexes. We also cannot manipulate the filtered column.
What is the precedence of logical operators, like NOT, AND, OR, and so on?
NOT precedes the AND and OR operators. AND precedes the OR operator. Remember the operations that are in parentheses has more precedences than NOT, AND and OR.
Note for this chapter
Review the table for how to use LIKE wildcards.
What is the standard way to specify a date?
Like this: ‘YYYYMMDD’
Is guaranteed the order of a query?
No, it isn’t. You guarantee the order of a query when you specifiy a ORDER BY clause.
What is the default direction of sorting?
Ascendent.
When the ordering is deterministic?
When you guarantee the order of the results. For sample, it the values of City columns aren’t unique, that means the order is not deterministic and is not guaranteed. But if you order by city and employeerId, you guarantee the order because employeerId is unique.
When you order a result by a column which allows NULL, how SQL Server treats this?
If you specify the order to be ascedent, then NULLs value will be in the beginning of the result. Otherwise, if you specifiy the order to be descendent, the NULLs value will be on the bottom.
What is the difference between the result of a query with and one without an ORDER BY clause?
Without an ORDER BY clause, the result is relational (from an ordering perspective);
with an ORDER BY clause, the result is conceptually what the standard
calls a cursor.
What’s the TOP clause?
With the TOP option, you can filter a requested number or percent of rows from the query
result based on indicated ordering. You specify the TOP option in the SELECT clause followed
by the requested number of rows in parentheses (BIGINT data type). The ordering specification
of the TOP filter is based on the same ORDER BY clause that is normally used for presentation
ordering.
What is the syntax to specify a percent of rows to be filtered?
n = input SELECT TOP (@n) PERCENT ...