SQL Fundamentals · SQL Foundations
25 cards
Values, Types, and Expressions
-
Quick check
A counter column will hold values in the low millions and needs no special tuning. Which whole-number type is the documented default choice, and what happens if a value ever exceeds its range?
Asmallint, and an out-of-range value is widened automatically
smallint is reserved for cases where disk space is at a premium, and no type silently widens itself to fit a value.
Binteger, and an out-of-range value raises an error
Right. integer is the balanced default for range, storage, and performance, and a value outside the allowed range is rejected with an error.
Cbigint, and an out-of-range value is rounded to the nearest limit
bigint exists for ranges that integer cannot hold, and nothing rounds a value to a range limit.
2 / 25
-
Quick check
A numeric value is written with two digits before the decimal point and four after it. What are its precision and its scale?
AA precision of four and a scale of two
Four and two reverse the reading: neither figure counts only the digits before the point.
BA precision of two and a scale of four digits
Precision is never the count of the leading digits alone; it covers both sides of the point.
CA precision of six, with a scale of four
Right. Precision counts all six significant digits, while scale counts only the four fractional ones.
5 / 25
-
Quick check
A ledger column stores monetary amounts that must be summed without rounding drift, and equality tests on balances must behave predictably. Reporting speed is secondary. Which type fits?
Anumeric, with a declared precision and scale
Right. numeric is the type recommended for monetary amounts and exact calculations, and its slower arithmetic is the accepted trade.
Breal, because it stores each value in less space
real is an inexact, variable-precision type, so stored amounts can drift and equality tests can surprise you.
Cdouble precision, because it offers the widest documented range of digits
double precision is also inexact; more digits of precision does not make its comparisons dependable.
7 / 25
-
Keep your progress in the app
That’s 3 of 11 quick checks. In the app they stay answered, and every lesson remembers where you left off.
-
Quick check
A short value is stored into a fixed-length character column. How is it held?
ARejected, because the declared width was not filled by the value
A shorter value is perfectly legal; only a longer one raises an error, and then only when the excess is not spaces.
BPadded with spaces out to the declared width
Right. The blank-padded character type widens a short value with spaces and stores and displays it that way.
CStored exactly as written, with no padding
Storing the value exactly as written is what character varying does, not the fixed-length type.
9 / 25
-
Quick check
An audit column must record a calendar date and a clock time in one value, and the zone in which the moment was recorded must be part of what is stored. Which declaration fits?
Atimestamp with time zone
Right. Only the with-time-zone spelling of the combined type carries both halves of the moment and its zone.
Btimestamp without time zone, which keeps the date and the clock time
This spelling does hold the date and the time, but it records no zone information at all.
Ctime with time zone, which keeps the clock time and its zone
A time-only type carries the zone but drops the calendar date, so one required component is missing.
12 / 25
-
Quick check
An arithmetic expression mixes an addition and a multiplication with no parentheses. How is it grouped, and how can that grouping be changed?
AAddition binds first, and a cast is what regroups the expression
Addition is the looser of the two, and a cast changes a value's type rather than the grouping of an expression.
BThe operators apply from left to right as written
Left-to-right applies between operators of the same precedence, not between two of different precedence.
CMultiplication binds first, and parentheses are what regroup it
Right. Multiplication binds more tightly than addition, and parentheses are the documented way to impose another reading.
14 / 25
-
Quick check
How does the BETWEEN predicate treat the two endpoint values of its range?
AOnly the lower endpoint is included
The endpoints are not treated differently from each other; neither one is singled out.
BBoth endpoints are included in the range
Right. BETWEEN includes both endpoints, so a value equal to either of them passes the test.
CNeither endpoint is included, so the range is strictly between them
An exclusive range is not what BETWEEN provides; it has to be written out with strict comparisons.
17 / 25
-
Quick check
Which ordering describes how the logical operators bind, from the tightest to the loosest?
ANOT, then AND, then OR
Right. Negation binds most tightly, conjunction next, and disjunction loosest, so an unparenthesised mixture groups in that order.
BAND, then OR, and finally NOT
Negation is the tightest of the three, so it cannot come last in the ordering.
COR first, then NOT, and finally AND
Disjunction is the loosest of the three, so it cannot bind more tightly than the other two.
19 / 25
-
Quick check
A label must join a text prefix to a numeric column with the concatenation operator, and the code must not depend on the engine accepting a non-string operand. What is the dependable approach?
AJoin the operands directly, since one is already text
Joining directly works only because one side is a string, which is exactly the accommodation the requirement rules out.
BConvert the text prefix to the column's numeric type first
Converting the string side to a number removes the string operand the operator needs, so nothing is left to join.
CCoerce the numeric column to text explicitly before joining it
Right. Inserting an explicit coercion to text is what makes a non-string input acceptable without leaning on that accommodation.
21 / 25
-
Quick check
A function declares three parameters, the second and third carrying defaults. Which call form can supply the third while leaving the second at its default?
ANamed notation, which can omit any combination of defaulted parameters
Right. Named notation matches each argument to its parameter by name, so any defaulted parameter can be skipped.
BPositional notation, which may omit a parameter at any position
Positional notation can only drop defaulted parameters from the right, so the second cannot be skipped while the third is supplied.
CNamed notation, provided its named arguments come first
Named arguments can never come before positional ones: mixed notation puts the positional arguments first.
23 / 25
-
Quick check
Which summary keeps the type and expression rules straight?
AFloating point is the exact type for money, and BETWEEN excludes its endpoints
The floating-point types are documented as inexact, and BETWEEN treats both endpoint values as included.
Bnumeric is the exact type for money, BETWEEN includes both endpoints, and parentheses override precedence
Right. Exactness comes from numeric, the range test is inclusive, and grouping is changed only with parentheses.
Ccharacter varying pads its values, and evaluation order runs strictly from left to right
The blank-padded fixed-length type is the one that pads, and the order of evaluation of subexpressions is not defined.
25 / 25
-
11 quick checks · then the test
In the app, finishing the quick checks opens this lesson’s 10-question test, and the ones you miss come back exactly when you’re about to forget them.
The whole course, on your phone
Lessons you can read, audio you can listen to on the way to work, and practice that remembers what you got wrong.