1 00:00:00,000 --> 00:00:04,987 [MUSIC] 2 00:00:04,987 --> 00:00:09,240 Let's remind ourselves of the CRUD acronym and what we know so far. 3 00:00:09,240 --> 00:00:14,680 We know that to create a ruin database, we use the keyword INSERT. 4 00:00:14,680 --> 00:00:17,650 For reading information, we use SELECT. 5 00:00:17,650 --> 00:00:19,120 But how about UPDATE? 6 00:00:19,120 --> 00:00:23,940 Unlike the other two it's not different from the word used in the acronym. 7 00:00:23,940 --> 00:00:24,670 It's UPDATE. 8 00:00:27,110 --> 00:00:31,020 To write an UPDATE statement, you'd write something like this. 9 00:00:31,020 --> 00:00:35,620 UPDATE, the table name, a cue word we haven't used before 10 00:00:35,620 --> 00:00:41,220 SET because we want to set the value of a column, next the column name, 11 00:00:41,220 --> 00:00:45,440 then the equal symbol and then the value. 12 00:00:45,440 --> 00:00:49,130 Now the equal sign in this case is not doing the same thing 13 00:00:49,130 --> 00:00:52,520 as what it would do in a condition in a WHERE clause. 14 00:00:52,520 --> 00:00:57,060 In the WHERE clause, it's the equal to or equality operator. 15 00:00:57,060 --> 00:01:01,470 In the UPDATE statement, it's know as an assignment operator. 16 00:01:01,470 --> 00:01:05,190 This is because we're assigning a new value 17 00:01:05,190 --> 00:01:08,450 to an existing value with a given column name. 18 00:01:08,450 --> 00:01:10,220 Let's see this in action. 19 00:01:10,220 --> 00:01:12,870 Let's first take a look at the patrons table. 20 00:01:12,870 --> 00:01:16,970 Imagine we wanted to give a copy of this database to an outsource developer and 21 00:01:16,970 --> 00:01:20,810 you wanted to anonymize any sensitive data of your patrons 22 00:01:20,810 --> 00:01:24,510 while giving an accurate representation of the user dataset. 23 00:01:25,740 --> 00:01:33,170 Let's use the template from before and change all the last names to anonymous. 24 00:01:34,690 --> 00:01:36,530 The table name is patrons. 25 00:01:38,780 --> 00:01:41,347 The column name is last_name. 26 00:01:46,441 --> 00:01:50,587 And then the value of the text Anonymous. 27 00:01:56,591 --> 00:01:58,250 Let's execute the query. 28 00:01:59,790 --> 00:02:03,560 And it updates all the last names in our table to Anonymous. 29 00:02:03,560 --> 00:02:05,275 But we still have zip codes and 30 00:02:05,275 --> 00:02:08,577 email addresses that could be tracked back to somebody. 31 00:02:08,577 --> 00:02:12,523 Let's update both the email and the zip_code. 32 00:02:12,523 --> 00:02:20,506 To do this, we can use a single statement with each assignment separated like this. 33 00:02:20,506 --> 00:02:22,444 Let's write our statement now. 34 00:02:25,164 --> 00:02:28,410 Let's change the table to patrons. 35 00:02:28,410 --> 00:02:30,200 The first column is email. 36 00:02:32,010 --> 00:02:38,016 The second column is zip_code with the relevant values. 37 00:02:51,664 --> 00:02:58,877 We've got the email as anon@email.com and the zip codes set to five 5s.