Post midterm SQL Flashcards

(36 cards)

1
Q

How are alias that include whitespace referenced outside of the SELECT statement?

A

in brackets: [alias name].

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

DATEDIFF arguments in order:
DATEDIFF(1,2,3)

A

1: time metric.
2: date1, subtracted from date2
3: date2.

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

What is the use and data type output from MONTH(), YEAR(), or DAY()?

A

Use: isolate a time metric in a date data type.
Output: integer.

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

What is the Syntax for OFFSET & FETCH?

A

OFFSET ?? ROWS
FETCH NEXT ?? ROWS ONLY;

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

How do you filter for NULL or NON NULL values in the WHERE clause (Syntax)?

A

“attribute IS NULL” or “attribute IS NOT NULL.”

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

The 5 aggregate functions can be sorted into two categories based on output. What are they and what are their possible outputs?

A

COUNT(), AVG(), and SUM() create numeric outputs. They can be decimal or integer.
MIN() and MAX() can have string, numeric, or date outputs.

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

What two ways can you use COUNT() to find the number of rows in a table?

A

COUNT(PK_attribute) or COUNT(*).

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

What does DISTINCT do?

A

Selects unique values from the first attribute in the SELECT statement.

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

What stipulate does the use of GROUP BY put on the SELECT statement?

A

All SELECT statement attributes must be either in the GROUP BY clause or an aggregate function.

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

You can assign DESC order to each attribute in ORDER BY clause. True or False?

A

True.

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

Alphabetical Ascending

A

A to Z.

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

Alphabetical Descending

A

Z to A.

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

Date Ascending

A

Oldest date to newest date.
2003 to 2024.

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

Date Descending

A

Newest date to oldest date.
2024 to 2003.

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

CONCAT(IDNum, State) is ordered as a number because the values start with integers. True or false?

A

False. They are treated as alphanumeric values.

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

How is OVER(PARTITION BY …) used? What a syntax example?

A

Used with an aggregate to display the aggregate alongside each record of certain groups. It appears in the SELECT statement.
Ex: “AVG(Salary) OVER(PARTITION BY Gender).”

17
Q

What does COUNT(*) OVER() do in the SELECT statement?

A

Returns total number of rows which is displayed with each row retrieved.

18
Q

What is the syntax for a CASE column in the SELECT statement?

A

CASE
WHEN (…) THEN ‘value’
WHEN (…) THEN ‘value’
ELSE ‘value’
END AS ‘Alias’

19
Q

Components in a CASE column in the SELECT statement?

A

CASE, WHEN, THEN, ELSE, & END.

20
Q

ALTER is DML and UPDATE is DDL. True of False?

A

ALTER is data definition language and UPDATE is data manipulation language.

21
Q

You cannot use CASE within UPDATE. It must be UPDATE SET WHERE. True of False?

22
Q

How do you use ALL or ANY?

A

They are used in non-correlated subqueries to get the compare the MAX() or MIN() of the inner query respectively. They go right before the inner query.
Ex: “WHERE Salary > ANY (…);”

23
Q

How do you hardcode record labels (SYNTAX)?

A

“SELECT ‘string’ AS ‘ ‘ …”
There must be one whitespace in the alias.

24
Q

ERROR_NUMBER()

A

Returns the error number when an error is caught, part of the Catch in a procedure.

25
ERROR_MESSAGE()
Returns the error message when an error is caught, part of the Catch in a procedure.
26
Declare a local variable and assign a value.
"Declare @variable_name" "SELECT @variable_name=AVG(Salary)"
27
SCOPE_IDENTITY()
Used when updating values with a procedure. It makes the update only to the most recent record. Ex: "WHERE EmpID = SCOPE_IDENTITY()."
28
Benefits of Procedures?
Enhanced security, enhanced performance, sharing, and centralization.
29
Sequential File Org
Records are recorded in sequence of PK values. A program scans the file from beginning to end. Useful in an operation involving the majority of records.
30
Hashing File Org
Technique for directly searching the location data on a disk using a hash function. Uses MD2 (128 Bits, Char(16)) or SHA2_512 (512 Bits, Char(64)). Best when looking for discrete, precise, or random records.
31
Indexing File Org
Creates an index table with an index value (pointers) and PK column. The indexes are used for results. Best used when returning a range, joins, where conditions, or aggregate functions. This is the default for RDBMS.
32
B+ Index Search
Binary tree search: starts at a root node and works its way through the tree (internal nodes) to find leaf nodes the quickest. Tree structure needs to be rebalanced or rebuilt regularly for efficiency.
33
Create a non-clustered index.
CREATE INDEX index_name AS table _name (attr1[, attr2]);
34
What does MAX(Date) and MIN(Date) return?
MAX(Date) finds the most recent date. MIN(Date) finds the furthest date in the past.
35
Date Descending
most recent date to oldest date.
36
Date Ascending
oldest date to most recent date.