Chapter 1. Manage data with Transact - SQL Flashcards
What are the mathematics roots that originated the relational model?
Set theory and Predicate Logic.
How SQL attempts to represent a relation?
With a table.
What does have a relation in the relational model?
A relation has a heading and a body. A heading is a set of attributes, each attribute has a name and a type. A body is a set of tuples, and each tuple’s heading is the relation’s heading. SQL represents the set of attributes -the heading- as columns, and the set of tuples -the body- as rows.
What is a set?
A set should be considered as a whole. This means that we don’t interact with individual elements of the set, rather with the set as a whole.
What’s a predicate?
A predicate is an expression that when attributed to some object, makes a proposition either true or false.
How a result can be relational?
The order needs to be arbitrary, this mean there’s not an order specified. The result set shouldn’t has duplicates. All columns or expression needs to be named, and each name needs to be unique.
How a column can be aliased?
By using the keyword “AS” after the column or an expression. For example:
SELECT col1, col2 AS Columna, col3
FROM SampleTable;
What means three valued predicate logic?
It means a predicate can be either true, false or unknown. It’s unknown when at least one of the operand has a missing value (NULL in SQL).
What’s the difference between called row as record, and column as field?
Fields and records are physical. Fields are what you have in user interfaces in client applications, and records are what you have in files and cursors. Tables are logical, and they have logical rows and columns.
What’s NULL?
It’s a mark that represent missing values.
What’s the keyed-in-order of a query?
It’s the order in which the clauses of a query should be written:
- SELECT
- FROM
- WHERE
- GROUP BY
- HAVING
- ORDER BY
What’s the logical query processing?
It’s how logically a query is processed:
- FROM
- ON
- OUTER
- WHERE
- GROUP BY
- CUBE | ROLLUP
- HAVING
- SELECT
- DISTINCT
10 ORDER BY - TOP
What’s the difference between the WHERE clause and the HAVING clause?
The WHERE it’s evaluated before the rows are grouped, so it evaluates the predicate per row. The HAVING clause it’s evaluated after the rows are grouped, so it evaluates the predicate per group.
Why an alias created in the SELECT clause doesn’t wok in the FROM clause?
Because the FROM clause it’s evaluated before the SELECT clause, so the alias created in the SELECT clause isn’t yet created at the FROM clause.
What is the difference between T-SQL and SQL?
SQL is a standard, while T-SQL is a dialect of SQL.