Mastering PyCharm Transcripts
Lecture: Modifying data with the console
0:01 The final operation we want to work with here
0:03 is to possibly change the schema,
0:05 what if we need to add a column, or add an index or something like that,
0:08 we can go over here and right click and say modify column for existing ones
0:13 here we could change stuff about it like it could become unique
0:16 or autoincrementing, or something like that
0:20 we could also go to the keys, go to the indexes
0:24 and say we want to add an index on whatever, right
0:29 go in here and add those things.
0:32 So we can edit it on the column by column
0:37 or probably it makes more sense to modify the table like so,
0:40 so we come over here and basically it was
0:43 as if we had double clicked one of these things
0:45 it doesn't really matter that much
0:47 but we could add say a column here
0:49 and this will be rating, and this is going to be an int,
0:53 and the default will be two,
0:56 and yeah, it's fine, we'll just go with that.
1:00 We can either execute this in the database,
1:02 and notice this, this is really sweet, alter table,
1:05 this is the stuff I always forget when I'm working with relational databases,
1:08 oh yeah, what's the DDL to change the type of a column
1:12 but it has data in it, so you have to like transform, like— what do I do.
1:16 This is the kind of stuff you do right here, so here's the script
1:19 and I could hit just boom, execute it and it will modify the database
1:23 or I could say just open this here in this editor
1:27 and I could make these changes and when I'm ready,
1:29 I push this button and run it, and then I make the changes,
1:32 let's go over here comment that out and run this,
1:35 alter table, one row is affected that sounds like something happened
1:41 and let's go resync, oh there is a rating, that's an integer,
1:44 I don't like it anymore, we'll go over here and we can just remove it.
1:53 Alright, so we're going to begin a transaction
1:55 drop a bunch of stuff, recreate it, that's pretty intense
1:57 but if we do that now our rating is gone again,
2:00 so this modifying data— not the simplest thing to do in relational databases,
2:05 like I said at the start, I think this is one of the harder parts
2:08 to evolve your database especially once it has data in it,
2:11 but, not too bad with the tools we have at hand here.