Effective PyCharm (2021 edition) Transcripts
Chapter: Databases
Lecture: Modifying the DB schema

Login or purchase this course to watch this video and the rest of the course contents.
0:00 You just have to modify data.
0:01 What if we want to modify the structure of the table itself.
0:05 So we can come over here and actually work on these various things,
0:09 we come over and say I'd like to modify the column and that will let us
0:11 actually work on the last updated column.
0:14 But generally you want to work at I guess at least the table level.
0:18 So we'll come over here. It's a modified table and let's give it some room
0:24 Here. You can see all of the columns that if I click on one I
0:27 could do things like remove it here and so on.
0:30 You can see the keys, the indexes and the foreign keys there are known for
0:34 this table. We come over here and I could actually add one.
0:37 I could say what we're gonna do is we're going to have a column called rating
0:41 that's going to be an integer and it's a default value is 3.
0:46 How cool is that? Look at what is below though here is the actual SQL
0:52 DDL script that you need to run to make this change and I think
0:57 that that is fantastic because these are the kinds of things I always forget.
1:01 What's the altar table thing for changing the column name.
1:05 If there's data there. You know,
1:06 things like that get really complicated.
1:09 Now I could push this button and it will happen directly or I could actually pull
1:13 this down and just stay open in the editor like so and I'm not really sure
1:19 that I want to run this yet.
1:21 So here it is in the editor and I could decide or I could do some
1:24 sort of transaction or I could match up a bunch of them so if we come
1:27 over here highlight that and we run it got some output here and notice we ran
1:33 this and it completed. That looks pretty good.
1:37 You don't see it already did refresh.
1:39 I was thinking it wouldn't refresh.
1:40 There we go. Well here's our rating that we created so we could come over
1:44 and run this again and now we should have our rating in here somewhere.
1:51 Perfect. You see now all of our entries have a rating and their default value
1:56 of three. Super cool. Huh?
1:59 All right so let's go ahead and take that away again.
2:00 We can come up we'll modify and then just hit the minus.
2:06 Gonna do a whole bunch of work to safely remove that and then put everything back
2:10 like it was. But notice right there our rating is now gone again.
2:14 So if you need to modify the structure of one of these tables well there's a
2:18 really cool way to do it.
2:19 Just go here do it in the editor and then hit save.
2:23 Either generate a DDL.
2:24 Transformation script like we did the first time or just hit execute and make it happen right away.