1 00:00:00,060 --> 00:00:06,420 Before we move on to our next string function, which is replace, I want to talk about how we can use 2 00:00:06,420 --> 00:00:08,820 a code editor to format our SQL. 3 00:00:08,850 --> 00:00:10,110 This is totally optional. 4 00:00:10,290 --> 00:00:16,050 It really has nothing to do with my SQL, but it does have to do with making our code more readable. 5 00:00:16,200 --> 00:00:22,620 So I showed and I've shown this many times, it doesn't matter how we type a single query. 6 00:00:22,620 --> 00:00:27,810 I mean, it matters in terms of having the right spaces in commas and all the syntax, but in terms 7 00:00:27,810 --> 00:00:30,900 of how we break it up across lines, SQL doesn't care. 8 00:00:31,230 --> 00:00:33,950 But from a human perspective, it should matter. 9 00:00:33,960 --> 00:00:37,530 This is a little tricky to read the way I have it divided here. 10 00:00:37,590 --> 00:00:39,840 So we can format this code. 11 00:00:39,840 --> 00:00:43,710 We don't have to do it ourselves depending on the tool that you're using. 12 00:00:43,710 --> 00:00:48,330 So if I'm using my SQL workbench, this little paintbrush here, I believe. 13 00:00:48,960 --> 00:00:51,080 Come on, show me the hint. 14 00:00:51,090 --> 00:00:51,570 There it is. 15 00:00:51,570 --> 00:00:54,110 Beautify or reformat the SQL script. 16 00:00:54,120 --> 00:00:57,990 If I click that, well, let me make sure I think I have to have this selected. 17 00:00:58,020 --> 00:00:58,710 There we go. 18 00:00:58,980 --> 00:01:01,460 It beautifies it in one way at least. 19 00:01:01,470 --> 00:01:05,940 Remember, there's many different ways of formatting SQL, but this is still better than what I had 20 00:01:05,940 --> 00:01:06,750 before. 21 00:01:06,860 --> 00:01:09,390 As you can see there, it's easier to understand. 22 00:01:09,810 --> 00:01:13,650 But if I do it over here, let's take the same exact code. 23 00:01:14,620 --> 00:01:17,140 But paste it into DB gates. 24 00:01:17,140 --> 00:01:19,140 Just another one of these tools. 25 00:01:19,150 --> 00:01:24,730 I can right click and go to format code and I think I like this one significantly more. 26 00:01:24,760 --> 00:01:30,340 The way that it formats our code in DB gate just looks good to me, indented and all that stuff. 27 00:01:30,700 --> 00:01:35,620 And then we even have something like vs code, just a regular text editor. 28 00:01:35,620 --> 00:01:44,260 I'm working in a SQL file and let me mess this up somewhat so that we have a reason to format it again. 29 00:01:44,260 --> 00:01:45,460 Let's say it's like this. 30 00:01:45,460 --> 00:01:51,310 I'm not a fan of that, so what I can do is open the command palette and if you don't know vs code, 31 00:01:51,310 --> 00:01:57,850 this really isn't worth worrying about, but command shift P And you can click on format, document 32 00:01:57,850 --> 00:02:02,770 or search for format document, but it's probably going to complain that I don't have a SQL formatter 33 00:02:02,770 --> 00:02:03,280 yet. 34 00:02:03,280 --> 00:02:04,420 So here we go. 35 00:02:04,420 --> 00:02:07,990 I'm going to install the one that it suggests SQL formatter. 36 00:02:08,050 --> 00:02:11,950 It's installing now and it should be done. 37 00:02:11,950 --> 00:02:13,360 So let's try that again. 38 00:02:13,360 --> 00:02:18,150 I'm going to format document and I have to change the default formatter. 39 00:02:18,460 --> 00:02:18,940 Sure. 40 00:02:20,130 --> 00:02:20,840 There we go. 41 00:02:20,850 --> 00:02:24,200 And it formatted it for me, so I shouldn't have to go through all those steps. 42 00:02:24,210 --> 00:02:26,520 Next time, let me mess it up again. 43 00:02:28,520 --> 00:02:29,390 Let's say. 44 00:02:29,390 --> 00:02:31,490 I mean, the way I've messed it up here is beyond repair. 45 00:02:31,490 --> 00:02:34,490 I have to have spaces for the actual keywords. 46 00:02:34,910 --> 00:02:41,450 But now I have this set up, so every time I save it auto format, command shift P I can do it manually. 47 00:02:41,450 --> 00:02:42,440 Format document. 48 00:02:42,440 --> 00:02:44,120 This is the shortcut as well. 49 00:02:44,510 --> 00:02:45,440 And there we are. 50 00:02:45,530 --> 00:02:52,280 So it just depends on what text editor you're using or what SQL tool or honestly, you can even just 51 00:02:52,280 --> 00:02:53,480 use a web browser. 52 00:02:53,510 --> 00:02:58,340 If you search online, you can find different code, beautifies fires or SQL for matters. 53 00:02:58,370 --> 00:03:02,410 None of them are terribly pretty, but here's one. 54 00:03:02,420 --> 00:03:03,410 I'll pay some code in. 55 00:03:03,410 --> 00:03:04,910 Let me mess it up again. 56 00:03:06,130 --> 00:03:08,440 Let's do maybe something like that. 57 00:03:08,950 --> 00:03:11,860 Make sure that I tell it I'm using my SQL. 58 00:03:11,890 --> 00:03:13,630 It shouldn't really matter that much. 59 00:03:14,080 --> 00:03:17,320 But let's do that and then format SQL. 60 00:03:18,790 --> 00:03:20,140 And that's how they format it. 61 00:03:20,140 --> 00:03:20,590 I don't know. 62 00:03:20,590 --> 00:03:22,190 I'm not a fan of that one as much. 63 00:03:22,210 --> 00:03:23,500 Let's try this over here. 64 00:03:23,530 --> 00:03:24,400 Same deal. 65 00:03:24,640 --> 00:03:25,660 Paste it in. 66 00:03:25,660 --> 00:03:29,620 And on the right hand side, we see a nice formatted version. 67 00:03:30,390 --> 00:03:34,320 So the moral of the story is that there's a lot of different ways to format code in general. 68 00:03:34,500 --> 00:03:38,210 There's no rule that says it has to be indented or that you have to have separate lines. 69 00:03:38,220 --> 00:03:39,880 It could be a single line of SQL. 70 00:03:39,900 --> 00:03:44,240 But if you are going to format it, I would be consistent in what you use. 71 00:03:44,250 --> 00:03:48,060 And one way to help you be consistent is to find a tool that you like. 72 00:03:48,090 --> 00:03:53,510 So if you're using SQL Workbench, then you can just go with the format that it does for you. 73 00:03:53,520 --> 00:03:58,570 Or if you're using DB Gate or VZ code, or you're just writing your own code on your own. 74 00:03:58,590 --> 00:04:00,380 You're not using any of these editors. 75 00:04:00,390 --> 00:04:02,580 You're working in Microsoft Word. 76 00:04:02,580 --> 00:04:04,520 You could write SQL in Microsoft Word. 77 00:04:04,530 --> 00:04:09,360 As long as you're saving it to a SQL file, then format it using an online tool. 78 00:04:10,230 --> 00:04:11,280 So not a requirement. 79 00:04:11,280 --> 00:04:17,430 And I won't be spending a lot of time formatting my code during the videos, but the end result code 80 00:04:17,430 --> 00:04:21,959 that I share with you will be formatted and should have a consistent pattern or a consistent format. 81 00:04:22,500 --> 00:04:25,140 Next up, we're moving on to more string functions. 82 00:04:25,140 --> 00:04:26,070 Replace.