Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
The update statement is used to change data in existing rows in a table. In this lesson, I'll be using the Scratch Database. And, I'm continuing with the test table that I created in the previous lesson. So if we say, SELECT * FROM test;, we can see the state of this. And we'll go ahead and we'll update a row. The update statement uses a where clause, just like the select statement. So, sometimes I like to start with a select statement with a where clause, like this, where a equals two.
And then I know that my where clause is. Selecting just the row that I want to change. This prevents me from accidentally updating rows that I don't intend to update. So for example, here I can say, UPDATE test, SET C equals Extra Funny. And we use that where clause that I've already typed and presumably debugged. And then after this I can say select star from test, and we can see the result. So there it is.
Sense of humor, extra funny. So you see that the. Update statement is used to change the data. I use the set clause here with the expression, the assignment expression to set the column that I'm interested in changing, and I use the where clause to select just the row or rows that I'm interested in updating. So, if I wanted to update it again I could change it again here I could say even funnier. And select go and you see there we have even funnier there in our results.
I can also set the value to null if I want and this effectively removes a value because remember. Null is the absence of value so I can use the key word null like this, and now we have a null there in our c column for a equals two. And you'll learn about null later in this chapter. So the update statement is used to change the data in particular columns in a table. You can select which rows are affected by using the where clause. Again, I'm going to leave this test table here for now and we'll be using it in the next lesson to learn about delete.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 101301 Viewers
61 Video lessons · 88061 Viewers
71 Video lessons · 71913 Viewers
56 Video lessons · 103737 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.