1 00:00:00,090 --> 00:00:01,589 Next up, we've got a quick aside. 2 00:00:01,589 --> 00:00:07,980 I want to talk about quotation marks When we are working with text in MySQL, which we have been right 3 00:00:07,980 --> 00:00:13,050 with all the var char columns, we provide those values instead of quotes. 4 00:00:13,260 --> 00:00:20,490 And technically in my SQL, depending on the mode that it's running in, you could use double quotes 5 00:00:20,490 --> 00:00:27,450 or single quotes, but that is not the case in other relational database management systems, aka other 6 00:00:27,450 --> 00:00:28,890 flavors of SQL. 7 00:00:28,950 --> 00:00:32,070 You don't want to use double quotes, you'll actually get errors. 8 00:00:32,070 --> 00:00:37,920 So it's a good practice to always use single quotes to wrap around whatever text we're providing when 9 00:00:37,920 --> 00:00:40,140 we're inserting or working with data. 10 00:00:40,200 --> 00:00:42,720 So let's make a really quick table. 11 00:00:42,720 --> 00:00:45,030 Let's call this shop. 12 00:00:45,030 --> 00:00:52,650 So create table shops and it's just going to have a single thing in there called Name, which is a bar 13 00:00:52,650 --> 00:00:56,090 chart of, I don't know, 100 OC. 14 00:00:56,530 --> 00:00:57,610 It looks like I have an error. 15 00:00:57,630 --> 00:01:01,530 Oh, I'm missing a second closing paren. 16 00:01:01,530 --> 00:01:05,400 So now I'm going to insert into this table insert into shops. 17 00:01:05,730 --> 00:01:14,970 We only have a name to insert and the values will just be something like, I don't know, Shoe emporium, 18 00:01:15,040 --> 00:01:15,600 whatever. 19 00:01:15,600 --> 00:01:15,870 All right. 20 00:01:15,870 --> 00:01:19,050 So we would use single quotes around this text. 21 00:01:19,050 --> 00:01:24,030 Technically, I could use double quotes with the way that I'm running my SQL right now, but it's best 22 00:01:24,030 --> 00:01:30,210 to not do that to avoid any confusion, especially if you try writing SQL in any other SQL database 23 00:01:30,210 --> 00:01:30,810 flavor. 24 00:01:31,080 --> 00:01:32,730 So this will work. 25 00:01:32,730 --> 00:01:38,670 But what about if I have a quote within my piece of text? 26 00:01:38,670 --> 00:01:45,090 Within my string, for example, we have something like Mario's Pizza. 27 00:01:45,300 --> 00:01:50,340 Well, this is going to be a problem because my SQL, just like any other programming language, if 28 00:01:50,340 --> 00:01:55,320 you've worked with them, is going to look for the opening quote in a closing quote and it thinks this 29 00:01:55,320 --> 00:01:58,110 is the piece of text and then it doesn't know what this is. 30 00:01:58,350 --> 00:02:04,320 So if I hit enter here, it first of all, doesn't even acknowledge that I've hit enter because I had 31 00:02:04,320 --> 00:02:07,830 an opening quote, a closing quote and then another opening quote. 32 00:02:07,830 --> 00:02:10,500 So it thinks this is all inside of a string. 33 00:02:10,500 --> 00:02:13,290 And in fact, right here, see how the cursor hit? 34 00:02:13,290 --> 00:02:15,090 The prompt has a quote there. 35 00:02:15,090 --> 00:02:19,230 That's my school's way of telling me, I'm waiting for you to close the quote. 36 00:02:19,230 --> 00:02:21,090 So we don't want to do this. 37 00:02:21,240 --> 00:02:22,050 We have an error. 38 00:02:22,050 --> 00:02:22,920 It doesn't work. 39 00:02:22,920 --> 00:02:30,780 So what we need to do instead is escape that quote and the way that we can escape a single quote or 40 00:02:30,780 --> 00:02:34,800 I guess an apostrophe in this case is to put a backslash in front of it. 41 00:02:34,920 --> 00:02:41,310 Now, my SQL will encounter that and it realizes that's not actually going to be a quote that is terminating 42 00:02:41,310 --> 00:02:42,420 this piece of text. 43 00:02:42,420 --> 00:02:47,220 It's just a quote, character inside this larger piece of text. 44 00:02:47,220 --> 00:02:53,910 So now if I do a select star from shops, we'll see that Mario's pizza is correctly formatted. 45 00:02:53,910 --> 00:03:00,150 Now, I can also do the same thing for double quotes if I needed double quotes inside of a piece of 46 00:03:00,150 --> 00:03:00,900 text. 47 00:03:01,170 --> 00:03:05,310 This is going to be a stupid example because there's no real reason to have double quotes here. 48 00:03:05,310 --> 00:03:08,700 But imagine I had a piece of text like she said. 49 00:03:08,970 --> 00:03:10,170 Ha ha. 50 00:03:10,650 --> 00:03:15,570 Well, if I have double quotes inside of single quotes, I don't have to escape anything. 51 00:03:15,570 --> 00:03:16,830 This is totally fine. 52 00:03:16,830 --> 00:03:17,880 Let's see what happens. 53 00:03:17,880 --> 00:03:21,390 Select star from shops. 54 00:03:21,630 --> 00:03:24,720 And those double quotes made it inside our piece of text. 55 00:03:24,900 --> 00:03:30,780 But if I did happen to be working with double quotes and then I wanted a double quote inside, I could 56 00:03:30,780 --> 00:03:32,910 escape that double quote character. 57 00:03:32,910 --> 00:03:37,380 But I don't think it's even worth showing you because as you'll recall, a couple of minutes ago, I 58 00:03:37,380 --> 00:03:43,260 talked about how you want to use single quotes on the outside, always in my SQL, even if you can get 59 00:03:43,260 --> 00:03:47,820 away with double quotes, sometimes just stick with single quotes to be consistent and you won't have 60 00:03:47,820 --> 00:03:48,720 to worry about it. 61 00:03:48,720 --> 00:03:54,510 And then if you need to escape single quotes, use the backslash, single quote character and if you 62 00:03:54,510 --> 00:03:57,360 need to, you could put double quotes inside of single quotes. 63 00:03:57,360 --> 00:03:58,800 There's no problem with that. 64 00:03:58,800 --> 00:04:00,660 That's just considered regular text. 65 00:04:00,660 --> 00:04:01,620 We can do whatever we want. 66 00:04:01,620 --> 00:04:05,820 And here it's just when we start an end, a string that we have to pay special attention. 67 00:04:06,150 --> 00:04:09,330 Okay, not the most exciting topic, but something that we have to get out of the way. 68 00:04:09,330 --> 00:04:10,020 So that's it. 69 00:04:10,020 --> 00:04:10,980 You're single quotes. 70 00:04:10,980 --> 00:04:12,390 That's all you should remember.