Questions: SQL: Creating and Modifying Tables

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A developer creates an `orders` table with a `price` column defined as VARCHAR(20). A query later computes AVG(price). What is the most likely problem?

ANo problem — VARCHAR can store numbers, and AVG converts them automatically
BThe query fails or produces incorrect results because VARCHAR columns don't support arithmetic aggregation reliably
CThe database automatically converts VARCHAR to NUMERIC for AVG whenever the values look like numbers
DThe query computes the average of the string lengths instead
Question 2 Multiple Choice

An `orders` table needs to ensure every row references a valid customer. Which constraint enforces this?

AUNIQUE constraint on the customer_id column in orders
BCHECK constraint verifying customer_id > 0
CFOREIGN KEY on customer_id referencing the primary key of the customers table
DNOT NULL constraint on customer_id in orders
Question 3 True / False

A PRIMARY KEY constraint on a column implies that the column is both NOT NULL and UNIQUE.

TTrue
FFalse
Question 4 True / False

Adding a NOT NULL constraint to a column is sufficient to ensure that column's values are correct and meaningful.

TTrue
FFalse
Question 5 Short Answer

Why is it better to enforce data quality rules (e.g., non-negative prices, valid category values) as database constraints rather than only in application code?

Think about your answer, then reveal below.