Foundations of Querying Flashcards

Work with Data Query data by using SELECT statements

1
Q

Writing in a __________ way is considered a best practice.

A

standard

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

True or False: You should consider a nonstandard option only when it has some important benefit to you that is not covered by the standard alternative.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Standard SQL is based on the _________ ________, which is a mathematical model for data management and manipulation.

A

relational model

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Define: Relational Model

A

A mathematical model for data management and manipulation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Who created and proposed the relational model?

A

Edgar F. Codd in 1969

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

A relation in the relational model is what SQL calls a _____.

A

table

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does a relation have?

A

A heading and a body.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Define: Heading

A

A set of attributes (what SQL attempts to represent with columns), each of a given type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Define: Attribute

A

An attribute is identified by name and type name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Define: Body

A

A set of tuples (what SQL attempts to represent with rows). Each tuple’s heading is the heading of the relation. Each value of each tuple’s attribute is of its respective type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Define: Set

A

A set is any collection M into a whole of definite, distinct objects m (which are called the elements of M) of our perception or of our thought.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

A _________ is an expression that when attributed to some object, makes a proposition either true or false.

A

predicate.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

True or False: A predicate is a parameterized proposition.

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

List the conditions that must be true in order for a set to be relational.

A

1) Must not have duplicates
2) No relevance to the order of the elements
3) All attributes must have names
4) All attributes must have unique names

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

SQL implements one general purpose mark called ____ for any kind of missing value.

A

NULL

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the mathematical branches that the relational model is based on?

A

Set theory and predicate logic.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is the difference between T-SQL and SQL?

A

SQL is standard; T-SQL is the dialect of and extension to SQL that Microsoft implements in its RDBMS - SQL Server.

18
Q

Multiple Choice: Why is it important to use standard SQL code when possible and know what is standard and what isn’t? (Choose all that apply)
A. It is not important to code using standard SQL.
B. Standard SQL code is more portable between platforms.
C. Standard SQL code is more efficient.
D. Knowing what standard SQL code is makes your knowledge more portable.

A

B and D

19
Q

Multiple Choice: Which of the following is not a violation of the relational model?
A. Using ordinal positions for columns
B. Returning duplicate rows
C. Not defining a key in a table
D. Ensuring that all attributes in the result of a query have names

A

D

20
Q

Multiple Choice: What is the relationship between SQL and T-SQL?
A. T-SQL is the standard language and SQL is the dialect in Microsoft SQL Server.
B. SQL is the standard language and T-SQL is the dialect in Microsoft SQL Server.
C. Both SQL and T-SQL are standard languages.
D. Both SQL and T-SQL are dialects in Microsoft SQL Server.

A

B

21
Q

Define: Logical Query Processing

A

The conceptual interpretation of the query that defines the correct result

22
Q

True or False: It is important to draw performance-related conclusions from logical query processing.

A

False

23
Q

Define: What is the “keyed-in order” of the main T-SQL query clauses?

A

1) SELECT
2) FROM
3) WHERE
4) GROUP BY
5) HAVING
6) ORDER BY

24
Q

Define: What is the logical query processing order of the six main query clauses?

A

1) FROM
2) WHERE
3) GROUP BY
4) HAVING
5) SELECT
6) ORDER BY

25
Q

This logical query processing clause indicates the tables you want to query and table operators like joins if applicable.

A

FROM

26
Q

This phase filters rows based on predicates.

A

WHERE

27
Q

Rows for which the predicate evaluate to _____, or evaluates to an unknown state, are not returned.

A

false

28
Q

Is it allowed to refer to an alias defined in the SELECT clause in a WHERE clause?

A

No. This is not allowed because the WHERE clause is evaluated before the SELECT clause.

29
Q

What is the function of the GROUP BY clause?

A

The GROUP BY clause defines a group for each distinct combination of values in the grouped elements from the input tables.

30
Q

If you want to refer to an element that is not in the GROUP BYU list, it must be contained within an _________ ________.

A

aggregate function (MAX, SUM, etc.)

31
Q

______ clause is responsible for filtering data based on a predicate, but is evaluated after the data has been grouped.

A

HAVING

32
Q

What is the difference between the WHERE and HAVING clause?

A

The WHERE clause is evaluated before rows are grouped, and is therefore evaluated per row. The HAVING clause is evaluated after rows are grouped, and therefore is evaluated per group.

33
Q

What is the function of the SELECT clause?

A

The SELECT clause evaluates any expressions in the SELECT list and produces the result set. It also assigns attributes with names if they are derived from expressions.

34
Q

What clause removes duplicate values from a query?

A

DISTINCT

35
Q

TRUE or FALSE? The fifth phase of logical query processing returns a relational set.

A

True. Assuming all other conditions have been met, the ORDER BY clause has not been evaluated yet, meaning the rows are in no particular order.

36
Q

Why are you not allowed to refer to a column alias defined by the SELECT clause in the same SELECT clause?

A

Because all expressions that appear in the same logical query processing phase are evaluated conceptually at the same point in time.

37
Q

This clause is responsible for returning the result set in a specific presentation order according to expressions.

A

ORDER BY

38
Q

Multiple Choice: Which of the following correctly represents the logical query processing order of the various query clauses?
A. SELECT > FROM > WHERE > GROUP BY > HAVING > ORDER BY
B. FROM > WHERE > GROUP BY > HAVING > SELECT > ORDER BY
C. FROM > WHERE > GROUP BY > HAVING > ORDER BY > SELECT
D. SELECT > ORDER BY > FROM > WHERE > GROUP BY > HAVING

A

B.

39
Q

Multiple Choice: Which of the following is invalid? (Choose any that apply)
A. Referring to an attribute that you group by in the WHERE clause
B. Referring to an expression in the GROUP BY clause; for example, GROUP BY YEAR(orderdate)
C. In a grouped query, referring in the SELECT list to an attribute that is not part of the GROUP BY list and not within an aggregated function.
D. Referring to an alias defined in the SELECT clause in the HAVING clause

A

C and D.

40
Q

Multiple Choice: What is true about the result set of a query without an ORDER BY clause?
A. It is relational as long as other relational requirements are met.
B. It cannot have duplicates.
C. The order of the rows in the output is guaranteed to be the same as the insertion order.
D. The order of the rows in the output is guaranteed to be the same as that of the clustered index.

A

A