SQL practice: Tables, Types and Constraints

Chapter 29 · 8 questions · included in full access

  1. Question 1 · easy

    Write the statement adding a CHECK that order_items.quantity must be above 0.

    Solve it in your browser
  2. Question 2 · easy

    Write the statement adding an email column to customers.

    Solve it in your browser
  3. Question 3 · medium

    Create a table suppliers with an auto ID, a name that can't be blank, a city, and a rating between 0 and 5.

    Solve it in your browser
  4. Question 4 · medium

    Add a DEFAULT of 'Pending' to orders.status. (Write the ALTER.)

    Solve it in your browser
  5. Question 5 · medium

    Which type would you choose for: a phone number, an invoice total, a delivery date, a "is active" flag? Justify the phone number one.

    Solve it in your browser
  6. Question 6 · medium

    Write a CHECK making sure products.unit_price is never below cost_price.

    Solve it in your browser
  7. Question 7 · hard

    Explain what would go wrong if orders.customer_id had no foreign key constraint.

    Solve it in your browser
  8. Question 8 · hard

    Create a temporary table named temp_lead_stage with two columns: lead_id (INT) and lead_score (NUMERIC(5,2)).

    Solve it in your browser

These questions are part of full access.

The first chapters of every track are free. Full access is a one-time payment.

See pricing