Learn SQL the Hard Way – Exercise 9 Updating Data

Here is my work for Exercise 9 Updating Data.

Exercise 9 code
Exercise 9 code

For exercise 9, we move to the Update part of CRUD. We change the names for Zed and his pet unicorn.
Extra Credit

  • Use UPDATE to change my name back to “Zed” by my person.id.

    Changed back! Still hilarious though.
  • Write an UPDATE that renames any dead animals to “DECEASED”. If you try to say they are “DEAD” it’ll fail because SQL will think you mean ‘set it to the column named “DEAD”‘, which isn’t what you want.
    Since none of the pets are dead, I first update Drogon’s dead status to true. I can then select all of the pets who are dead and rename them to “DECEASED”.

    Renaming dead pets to "DECEASED".
    Renaming dead pets to “DECEASED”.

    Drogon is now Deceased. :(
    Drogon is now Deceased. 😦
  • Try using a subquery with this just like with DELETE.
    I used a subquery to get a table of pet names where the pet age was less than 10. I then used UPDATE to set their names to Young One.

    Two Young Ones here!
    Two Young Ones here!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s