SQL programming Chap. 5-8 – Flashcards

Unlock all answers in this set

Unlock answers
question
You can use the AS keyword with the CREATE TABLE statement to create a copy of a table from a ____________________ statement.
answer
SELECT
question
By default, MySQL automatically commits changes to the database immediately after each INSERT, UPDATE, and ______________ statement that you issue.
answer
DELETE
question
When you code a column list in an INSERT statement, you can omit columns with default values and columns that allow ____________________________ values.
answer
null
question
To insert rows selected from one or more tables into another table with an INSERT statement, you code a/an ___________________________ in place of the VALUES clause.
answer
subquery select
question
When you code an UPDATE statement for one or more rows, the SET clause names the columns to be updated and the values to be assigned to those columns, and the ______________________ clause specifies the conditions a row must meet to be updated.
answer
WHERE
question
Which of the following statements is true when you use MySQL Workbench to run INSERT, UPDATE, and DELETE statements?
answer
By default, the changes are automatically committed to the database.
question
Assuming that all of the table and column names are spelled correctly, what's wrong with the INSERT statement that follows? INSERT INTO invoices (vendor_id, invoice_number, invoice_total, payment_total, credit_total, terms_id, invoice_date, invoice_due_date) VALUES (97, '456789', 8344.50, 0, 0, 1, '2012-08-31')
answer
The number of items in the column list doesn't match the number in the VALUES list.
question
The six clauses of the SELECT statement must be coded in the following order:
answer
SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY
question
Expressions coded in the HAVING clause
answer
can use aggregate search conditions but can't use non-aggregate search conditions
question
Expressions coded in the WHERE clause
answer
can use non-aggregate search conditions but can't use aggregate search conditions
question
Which of the statements below best describes the result set returned by this SELECT statement? SELECT vendor_id, SUM(invoice_total - payment_total - credit_total) AS column_2 FROM invoices WHERE invoice_total - payment_total - credit_total > 0 GROUP BY vendor_id
answer
The total unpaid balance due for each vendor_id
question
Which of the statements below best describes the result set returned by this SELECT statement? SELECT vendor_state, COUNT(*) AS column_2 FROM vendors GROUP BY vendor_state HAVING COUNT(*) > 1
answer
The number of vendors in each state that has more than one vendor
question
Code example SELECT vendor_state, vendor_city, vendor_name, COUNT(*) AS invoice_qty, SUM(invoice_total) AS invoice_average FROM invoices JOIN vendors ON invoices.vendor_id = vendors.vendor_id WHERE vendor_state < 'e' GROUP BY vendor_state, vendor_city, vendor_name HAVING SUM(invoice_total) > 500 ORDER BY vendor_state, vendor_city, vendor_name (Please refer to code example) When this summary query is executed, the result set will contain one summary row for
answer
each vendor with invoice totals over $500
question
All of the aggregate functions ignore null values, except for the ______________________________ function.
answer
COUNT(*)
question
If introduced as follows, the subquery can return which of the values listed below? WHERE vendor_id NOT IN (subquery)
answer
a column of one or more rows
question
If introduced as follows, the subquery can return which of the values listed below? WHERE (subquery)
answer
a subquery can't be introduced in this way
question
If introduced as follows, the subquery can return which of the values listed below? WHERE 2 < (subquery)
answer
a single value
question
If introduced as follows, the subquery can return which of the values listed below? WHERE invoice_total > ALL (subquery)
answer
a column of one or more rows
question
If introduced as follows, the subquery can return which of the values listed below? SELECT (subquery)
answer
a single value
question
If introduced as follows, the subquery can return which of the values listed below? FROM (subquery)
answer
a table
question
Code example SELECT vendor_name, COUNT(*) AS number_of_invoices, MAX(invoice_total - payment_total - credit_total) AS balance_due FROM vendors v JOIN invoices i ON v.vendor_id = i.vendor_id WHERE invoice_total - payment_total - credit_total > (SELECT AVG(invoice_total - payment_total - credit_total) FROM invoices) GROUP BY vendor_name ORDER BY balance_due DESC (Please refer to code example 7-1.) When this query is executed, the result set will contain
answer
one row for each vendor that shows the largest balance due for any of the vendor's invoices, but only if that balance due is larger than the average balance due for all invoices
question
Code example SELECT vendor_name, COUNT(*) AS number_of_invoices, MAX(invoice_total - payment_total - credit_total) AS balance_due FROM vendors v JOIN invoices i ON v.vendor_id = i.vendor_id WHERE invoice_total - payment_total - credit_total > (SELECT AVG(invoice_total - payment_total - credit_total) FROM invoices) GROUP BY vendor_name ORDER BY balance_due DESC (Please refer to code example 7-1.) When this query is executed, the number_of_invoices for each row will show the number
answer
of invoices for each vendor that have a larger balance due than the average balance due for all invoices
question
Code example SELECT vendor_name, COUNT(*) AS number_of_invoices, MAX(invoice_total - payment_total - credit_total) AS balance_due FROM vendors v JOIN invoices i ON v.vendor_id = i.vendor_id WHERE invoice_total - payment_total - credit_total > (SELECT AVG(invoice_total - payment_total - credit_total) FROM invoices) GROUP BY vendor_name ORDER BY balance_due DESC (Please refer to code example 7-1.) When this query is executed, the rows will be sorted by
answer
balance_due in descending sequence
question
Code example SELECT i.vendor_id, MAX(i.invoice_total) AS largest_invoice FROM invoices i JOIN (SELECT vendor_id, AVG(invoice_total) AS average_invoice FROM invoices GROUP BY vendor_id HAVING AVG(invoice_total) > 100 ORDER BY average_invoice DESC) ia ON i.vendor_id = ia.vendor_id GROUP BY i.vendor_id ORDER BY largest_invoice DESC (Please refer to code example 7-2.) When this query is executed, the result table will contain one row for
answer
each vendor in the table named ia
question
Numbers that don't include a decimal point are known as ____________________.
answer
integers
question
The DATETIME data type includes not only the date, but also a ________________________.
answer
time
question
When MySQL automatically converts one data type to another, it's known as a/an ______________________ conversion.
answer
implicit
question
The _____________________ function is an ANSI-standard function that you can use to perform an explicit conversion.
answer
CAST
question
All of the following values can be stored in a column that's defined as DECIMAL(6,2), except
answer
32492.05
question
Which uses the least amount of storage?
answer
they all use the same amount of storage (Just know that 'VARCHAR' saves the amount of characters plus one. The others save a fixed amount.)
question
The DATE data type can store
answer
dates only
question
The default date format for MySQL is _________________.
answer
yyyy-mm-dd
question
The ENUM data type stores values that are mutually exclusive. Which choice is not appropriate for the ENUM type?
answer
mushrooms, sausage, peppers
question
Scalar Function
answer
Operates on a single value and returns a single value
question
Aggregate Function
answer
Allow you to do jobs like calculate averages, summarize totals, or find the highest value for a given column, and you'll use them in summary queries
question
Column Functions
answer
Aggregate functions typically operate on the values in columns, they are sometimes referred to as this
question
summary query
answer
A query that contains one or more aggregate functions
question
subquery
answer
A SELECT statement that's coded within another SQL statement.
question
Four ways to introduce a subquery
answer
In a Where clause as a search condition In a HAVING clause as a search condition In the FROM clause as a table specification In the SELECT clause as a column specification
question
Nested Subquery
answer
Subquery in a Subquery
question
Correlated subquery
answer
A subquery that is executed once for each row in the main query. In contrase, an uncorrelated subquery is executed only once.
question
Uncorrelated subquery
answer
executed only once
question
Inline View
answer
Subquery that's coded in the FROM clause returns a result set that can be referred to as this
question
Comment
answer
double dash "--"
question
pseudocode
answer
not real code but like a rough draft
question
Implicit conversion
answer
automatic conversion
question
explicit conversion
answer
if you want to control how a conversion is performed you use this
Get an explanation on any task
Get unstuck with the help of our AI assistant in seconds
New