You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Raf Vergauwen be6e320bb9 v1 2 jaren geleden
README.md v1 2 jaren geleden
bulb.png initial upload 2 jaren geleden
question-mark.png initial upload 2 jaren geleden

README.md

How to insert update and delete data

Question Exercise 1

  1. Write an INSERT statement that adds this row to the Terms table:

    • terms- id: 6
    • terms_description: Net due 120 days
    • terms_due_days: 120
  2. Use MySQL Workbench to review the column definitions for the Terms table, and include a column list with the required columns in the INSERT statement.

Answer Solution 1



Question Exercise 2

  1. Write an UPDATE statement that modifies the row you just added to the Terms table.

  2. This statement should change the terms_description column to “Net due 125 days”.

  3. And it should change the terms_due_days column to 125.

Answer Solution 2

UPDATE
    terms
SET
    terms_description = "Net due 125 days",
    terms_due_days = 125
WHERE
    terms_id = 6;

Question Exercise 3

  1. Write a DELETE statement that deletes the row you added to the Terms table in exercise 1.

Answer Solution 3

DELETE FROM
    terms
WHERE
    terms_id = 6;

Question Exercise 4

  1. Write an INSERT statement that adds this row to the Invoices table:

    • invoice id: The next automatically generated ID
    • vendor id: 32
    • invoice_number: AX-014-027
    • invoice_date: 8/1/2018
    • invoice_total: $434.58
    • payment_total: $0.00
    • credit total: $0.00
    • terms id: 2
    • invoice_due_date: 8/31/2018
    • payment_date: null
  2. Write this statement without using a column list.

Answer Solution 4



Question Exercise 5

  1. Write an INSERT statement that adds these rows to the Invoice_Line_Items table:

    • invoice_sequence: 1
    • account_number: 160
    • line_item_amount: $180.23
    • line_item_description: Hard drive

    • invoice_sequence: 2

    • account_number: 527

    • line_item_amount: $254.35

    • line_item_description: Exchange Server update

  2. Set the invoice_id column of these two rows to the invoice ID that was generated by MySQL for the invoice you added in exercise 4.

Answer Solution 5



Question Exercise 6

  1. Write an UPDATE statement that modifies the invoice you added in exercise 4.

  2. This statement should change the credit_total column so it’s 10% of the invoice_total column.

  3. And it should change the payment_total column so the sum of the payment_total and credit_total columns are equal to the invoice_total column.

Answer Solution 6

UPDATE
    invoices
SET
    credit_total = invoice_total * 0.1,
    payment_total = invoice_total - credit_total
WHERE
    invoice_id = 115;

Question Exercise 7

  1. Write an UPDATE statement that modifies the Vendors table.

  2. Change the default account number column to 403 for the vendor with an ID of 44.

Answer Solution 7

UPDATE
    vendors
SET
    default_account_number = 403
WHERE
    vendor_id = 44;

Question Exercise 8

  1. Write an UPDATE statement that modifies the Invoices table.

  2. Change the terms_id column to 2 for each invoice that’s for a vendor with a default_terms_id of 2.

Answer Solution 8

UPDATE
    invoices
SET
    terms_id = 2
WHERE
    vendor_id IN (
                  SELECT
                    vendor_id
                  FROM
                    vendors
                  WHERE
                    default_terms_id = 2
                 );

Question Exercise 9

  1. Write a DELETE statement that deletes the row that you added to the Invoices table in exercise 4.

  2. When you execute this statement, it will produce an error since the invoice has related rows in the Invoice_Line_Items table.

  3. To fix that, precede the DELETE statement with another DELETE statement that deletes the line items for this invoice. (Remember that to code two or more statements in a script, you must end each statement with a semicolon.)

Answer Solution 9

DELETE FROM
    invoice_line_items
WHERE
    invoice_id = 115;

DELETE FROM invoices
WHERE
    invoice_id = 115;