1 00:00:00,210 --> 00:00:00,720 All right. 2 00:00:00,720 --> 00:00:04,019 It's time for a solution to the relatively painless update exercises. 3 00:00:04,030 --> 00:00:04,890 Let's get going. 4 00:00:04,920 --> 00:00:09,000 The first piece is to change Jackson's name to Jack. 5 00:00:09,480 --> 00:00:15,360 So as I mentioned two videos ago, I like to start by making sure I'm targeting the correct rows before 6 00:00:15,360 --> 00:00:16,710 I do any updating. 7 00:00:16,830 --> 00:00:19,530 So I'll do a select select start from cats. 8 00:00:19,890 --> 00:00:26,610 Select start from cats where and then name equals Jackson. 9 00:00:27,030 --> 00:00:30,490 And let's make sure I get back to the row I'm expecting. 10 00:00:30,510 --> 00:00:31,530 It's simple enough. 11 00:00:31,560 --> 00:00:35,200 There's one Jackson but imagine we were updating multiple rows. 12 00:00:35,220 --> 00:00:39,420 It's a good idea to verify what we're selecting before we actually do the update. 13 00:00:39,420 --> 00:00:48,090 So now I can say update and then we're going to do that set name to be, I believe it was supposed to 14 00:00:48,090 --> 00:00:49,020 be Jack. 15 00:00:50,200 --> 00:00:53,860 Where name equals Jackson. 16 00:00:54,040 --> 00:00:56,290 And there we go. 17 00:00:56,320 --> 00:00:59,930 Let's just do a select star from cats just to see our result. 18 00:00:59,950 --> 00:01:05,590 This is not really a good way to verify your results or that it worked in general if you have a lot 19 00:01:05,590 --> 00:01:06,130 of data. 20 00:01:06,130 --> 00:01:10,900 But if we have like seven rows, we can just quickly find out where's Jack? 21 00:01:11,680 --> 00:01:14,860 But if we had 10,000 rows, that's not not going to work for us. 22 00:01:14,860 --> 00:01:18,240 So we might want to select based off of something else and narrow it down. 23 00:01:18,250 --> 00:01:19,720 Anyway, so that part worked. 24 00:01:19,750 --> 00:01:23,410 Next up, change Ringo's breed to British short hair. 25 00:01:23,410 --> 00:01:24,490 So do the same thing. 26 00:01:24,490 --> 00:01:35,080 Select star from Cat and then I'll do where breed equals and then I'd rather I have that backwards where 27 00:01:35,080 --> 00:01:36,440 name equals Ringo. 28 00:01:36,460 --> 00:01:44,170 We're selecting by name and we're changing Ringo's breed from tabby to British Shorthair so we can keep 29 00:01:44,170 --> 00:01:48,970 that where portion and just delete the select and instead do an update. 30 00:01:48,970 --> 00:01:56,440 Cats set breed to be British Shorthair where name is Ringo. 31 00:01:56,800 --> 00:01:59,590 And again, I'll just do the easy cheating way. 32 00:01:59,590 --> 00:02:05,470 I'll just select everything from cats and we should see Ringo now is a British shorthair. 33 00:02:06,280 --> 00:02:11,230 And then finally update both Maine --, two ages to be 12. 34 00:02:11,710 --> 00:02:13,930 So once again, I'll follow the same process. 35 00:02:13,930 --> 00:02:15,580 Select Star from Cats. 36 00:02:15,580 --> 00:02:22,930 Before I do my update, I'm going to find out how many cats are there Where breed is Maine -- and 37 00:02:22,930 --> 00:02:23,590 there's two. 38 00:02:23,590 --> 00:02:25,020 And that's what I expect. 39 00:02:25,030 --> 00:02:28,390 I want to update both of them to be 12 years old. 40 00:02:28,390 --> 00:02:30,340 Yes, it doesn't make any sense. 41 00:02:30,340 --> 00:02:31,960 One is ten, the other is 11. 42 00:02:31,960 --> 00:02:33,520 There's a bug in our system. 43 00:02:33,610 --> 00:02:34,270 Who knows? 44 00:02:34,270 --> 00:02:37,750 So instead of selecting, I'm going to do an update. 45 00:02:38,410 --> 00:02:39,670 Update cats. 46 00:02:40,640 --> 00:02:45,290 Set age to be 12 where breed is Maine --. 47 00:02:45,890 --> 00:02:49,580 And then once again, let's verify select star from Cats. 48 00:02:49,580 --> 00:02:53,240 And we see those two Maine -- now have an age of 12. 49 00:02:53,720 --> 00:02:56,180 And that's it for our simple exercise. 50 00:02:56,180 --> 00:03:00,530 Hopefully you were able to go through that and not lose your mind out of boredom. 51 00:03:00,560 --> 00:03:01,970 Next up, deletion.