SQL Certification Exam 461 Flashcards
What three things make a nonrelational query relational?
- Every element has a name
- There are no duplicates
- There is no order
Name two approximate numeric data types
1) Real
2) Float
How many bytes is a float
8
How many bytes is a real?
4
What function generates a sequential DEFAULT identifier for a UNIQUEIDENTIFIER field?
NEWSEQUENTIALID()
What column attribute requires it contain a Unique identifier?
UNIQUEIDENTIFIER
What function returns the current date?
GetDate() returns DATETIME
What year range does DATETIME support?
1753 - 9999
What function returns the most accurate DateTime value?
SYSDATETIME returns DATETIME2
What is the year range for DATETIME2?
year 0001 to 9999
What function will return a part of a date (month, day, or year) as a scalar value?
DATEPART(month, string date)
What function returns a string value for a part of a date - and the month name spelled out?
DATENAME(month, string date)
What function adds a number of days, months, or years to a date?
DATEADD(month, 1, string date)
What function returns the difference between dates in days, months, or years?
DATEDIFF(month, start date, end date )
What function returns a substring?
SUBSTRING(string date, starting, length)
What function returns the string length in characters?
LEN
What function returns the string length in bytes?
DATALENGTH
What function replaces all occurrences of characters in a string?
REPLACE(string, ‘x’, ‘y’) replaces x’s with y’s
What function produces a string repeated n times?
REPLICATE(‘xyz’, 10) repeats xyz 10 times
What function replaces a series of characters with a new string?
STUFF(string, starting, length, string)
Show a simple form of CASE statement.
CASE scalar-expression WHEN 0 THEN 'No' WHEN 1 THEN 'Yes' ELSE 'Unknown' END AS alias
Show the advanced form of CASE statement.
CASE WHEN unitPrice < 20.00 THEN 'Low" WHEN unitPrice < 40.00 THEN 'Medium' ELSE 'High' END AS priceRange
What function returns the first of its arguments that is not NULL?
COALESCE(a, b, c, …)
What function performs and IF-THEN-ELSE?
IFF(expression, true, false)
What function takes a scalar and uses that to index into its argument list to select a value to return?
CHOOSE(index, arg1, arg2, arg3, …)
In expressions is AND processed BEFORE or AFTER the OR operator?
Before
LIKE wildcards: %
0 or more of any character
LIKE wildcards: _ (underscore)
any single character
LIKE wildcards: [ABCDE]
any one character in the list
LIKE wildcards: [0-9]
any one character in the range
LIKE wildcards ^ caret
NOT the following argument
OFFSET-FETCH requires what clause?
ORDER BY
example OFFSET-FETCH
after order by
OFFSET n ROWS FETCH NEXT m ROWS ONLY;
What does a CROSS JOIN produce?
Each row in Left paired with Each row in right
What does an INNER JOIN produce?
Produces pairing of Left and Right rows that match a predicate
What does a LEFT OUTER JOIN produce?
ALL rows from left and pairing those on the right that match a predicate
What does a RIGHT OUTER JOIN product?
ALL rows from the right and pairing those on the left that match a predicate.
What defines a self-contained subquery?
It has no dependency (references) on the outer containing query.
What is a correlated subquery?
One that references a column from the outer query or table.
List four types of Table Expressions.
1) Derived Tables
2) Common Table Expressions (CTEs)
3) Views
4) Inline table-valued functions
How is a derived table defined?
From (Select … returning a table of rows) as T
Show CTE form.
WITH myCTE AS ( Inner query ) Select ... FROM myCTE
Show View form.
CREATE VIEW myView
AS
SELECT … FROM table;
Show inline table-valued function form.
CREATE FUNCTION name(args) RETURNS TABLE
AS
RETURN
SELECT statement returning table;
Which function UNION or UNION ALL returns only DISTINCT pairs?
UNION… UNION ALL keeps all duplicates
What operator returns only rows that are DISTINCT between two sets.
query1 INTERSECT query2
What operator returns rows in the first that are not in the second set.
query1 EXCEPT query2
What date function returns the End of the Month value.
EOM(date)
Show the form of a GROUPING SET
GROUP BY GROUPING SETS ( ( colA, colB, YEAR(colC) ), ( colA ), ( YEAR(colC) ), ( ) )
What’s a CUBE GROUPING SET?
Defines all possible combinations of its argument: GROUP BY CUBE( A, B ); produces sets: ( A, B ) ( A ) ( B ) ( )
What does a ROLLUP GROUPING SET product?
Given an argument such as: GROUP BY ROLLUP ( country, state, city) it produces hierarchical sets: (country, state, city), (country, state), (country), ( )
Pivoting: rows are also known as _____
grouping element
Pivoting: columns are also known as _____
spreading element
Pivoting: data is also known as ______
aggregation element