1 00:00:00,120 --> 00:00:06,990 The next thing we'll see is how we can modify existing columns, not their name, but modify the actual 2 00:00:06,990 --> 00:00:08,430 column definition. 3 00:00:08,580 --> 00:00:16,079 So in this example, I'm altering the table suppliers to modify the biz name column so that it is a 4 00:00:16,079 --> 00:00:20,640 var car 100, whatever it was before it is now a var car 100. 5 00:00:21,150 --> 00:00:27,270 Now we have to be somewhat careful with this, of course, because if you had a numeric column that 6 00:00:27,270 --> 00:00:31,680 you were turning into text or text, you're turning into numeric or a date column, you're suddenly 7 00:00:31,680 --> 00:00:35,190 turning into an int that could cause a lot of issues. 8 00:00:35,190 --> 00:00:37,920 You want to you want to be very conscious of that. 9 00:00:37,920 --> 00:00:39,870 But I'm just going to show you a simple example. 10 00:00:39,870 --> 00:00:47,340 Let's say that I realized I wanted something to be not null and it was currently knowable and I want 11 00:00:47,340 --> 00:00:51,030 to make it a var car with a larger size. 12 00:00:52,350 --> 00:00:55,440 So we've got I don't know, let's go back to companies. 13 00:00:55,440 --> 00:01:00,190 We have var car 255 for name. 14 00:01:00,210 --> 00:01:02,040 Let's actually shrink that down. 15 00:01:02,130 --> 00:01:02,690 Sure. 16 00:01:02,700 --> 00:01:06,420 So I renamed that column to company name, if you remember. 17 00:01:06,420 --> 00:01:10,020 Here, let's do describe companies. 18 00:01:10,820 --> 00:01:11,600 Here we are. 19 00:01:11,630 --> 00:01:16,550 We see that company name is var two, five, five. 20 00:01:17,060 --> 00:01:19,520 So let's say maybe I want to add a default value. 21 00:01:19,520 --> 00:01:22,570 And I also want to make it a var card 100. 22 00:01:22,580 --> 00:01:26,030 We're enforcing a shorter limit for our var cards. 23 00:01:26,120 --> 00:01:28,310 This is stupid, but let's just do it. 24 00:01:28,490 --> 00:01:34,520 So I'll do an alter table companies if that's still the name, of course. 25 00:01:34,520 --> 00:01:36,440 And then modify. 26 00:01:36,560 --> 00:01:38,270 And what am I trying to modify? 27 00:01:38,300 --> 00:01:40,490 The company name column. 28 00:01:41,000 --> 00:01:41,450 Whoops. 29 00:01:41,450 --> 00:01:42,110 This way. 30 00:01:42,650 --> 00:01:43,700 Company name. 31 00:01:43,880 --> 00:01:47,030 And now I can say I want it to be a var char. 32 00:01:48,110 --> 00:01:54,380 Uh, 100 and then give it a default value of a name. 33 00:01:54,380 --> 00:01:55,820 Unknown Something like that. 34 00:01:55,820 --> 00:02:00,830 If you put a company in here, we don't know the name, then its default will be unknown. 35 00:02:02,480 --> 00:02:04,760 So right now it's var 255. 36 00:02:04,790 --> 00:02:05,210 Oh no. 37 00:02:05,210 --> 00:02:07,370 I have these quotes there that might cause me trouble. 38 00:02:07,370 --> 00:02:08,330 Let's try that again. 39 00:02:08,449 --> 00:02:09,650 All right, I run it. 40 00:02:09,650 --> 00:02:11,000 Let's describe. 41 00:02:11,690 --> 00:02:13,430 Where are you companies? 42 00:02:13,430 --> 00:02:18,080 It's still called company name, but now var 100 is the type. 43 00:02:18,080 --> 00:02:21,950 And we see that default is set to unknown. 44 00:02:22,070 --> 00:02:30,230 And if I were just to quickly insert into companies, we have company name and address values. 45 00:02:30,920 --> 00:02:33,800 Let's insert no company name. 46 00:02:33,800 --> 00:02:34,790 So I'm going to leave that off. 47 00:02:34,790 --> 00:02:36,830 That was the whole point I wanted to show. 48 00:02:36,830 --> 00:02:45,470 So let's only insert the address and address will be two five, five, four Rose Lane. 49 00:02:47,080 --> 00:02:54,670 And if I now select star from my companies, we see the default for company name kicked in, which is 50 00:02:54,670 --> 00:02:57,490 unknown, and that's what we get instead of null. 51 00:02:57,940 --> 00:02:58,600 All right. 52 00:02:58,600 --> 00:03:03,250 So that's how you can modify a column by changing its type. 53 00:03:03,280 --> 00:03:04,840 There's also a second option. 54 00:03:04,840 --> 00:03:11,530 If you wanted to rename a column and change its definition, you can use change. 55 00:03:11,530 --> 00:03:16,570 So I use this less often because a lot of the time I might just want to modify an existing column, 56 00:03:16,570 --> 00:03:17,530 not rename it. 57 00:03:17,620 --> 00:03:23,740 But if you use change, you have to say the current column name, then the new column name and then 58 00:03:23,740 --> 00:03:25,390 the new column definition. 59 00:03:25,420 --> 00:03:32,950 So this is saying take the supplier's table, change the business column, rename it to biz name, and 60 00:03:32,950 --> 00:03:35,560 set the definition to be a var of 50. 61 00:03:36,100 --> 00:03:38,300 So I don't think I need to show an example of that. 62 00:03:38,320 --> 00:03:40,470 It's the same concept, right? 63 00:03:40,480 --> 00:03:43,930 We just have to say old name, new name definition. 64 00:03:43,930 --> 00:03:48,340 Whereas when we modify, we don't have the opportunity to change the name of a column. 65 00:03:48,340 --> 00:03:49,600 But it's simpler. 66 00:03:49,690 --> 00:03:55,530 We only say, Here's the current name and the new definition for that current named column OC.