Effective PyCharm Transcripts
Chapter: Databases
Lecture: Modifying data with the console

Login or purchase this course to watch this video and the rest of the course contents.
0:01 The final operation we want to work with here is to possibly change the schema,
0:06 what if we need to add a column, or add an index or something like that, we can go over here and right click and say modify column for existing ones
0:14 here we could change stuff about it like it could become unique or autoincrementing, or something like that
0:21 we could also go to the keys, go to the indexes and say we want to add an index on whatever, right go in here and add those things.
0:33 So we can edit it on the column by column or probably it makes more sense to modify the table like so, so we come over here and basically it was
0:44 as if we had double clicked one of these things it doesn't really matter that much but we could add say a column here
0:50 and this will be rating, and this is going to be an int, and the default will be two, and yeah, it's fine, we'll just go with that.
1:01 We can either execute this in the database, and notice this, this is really sweet, alter table,
1:06 this is the stuff I always forget when I'm working with relational databases, oh yeah, what's the DDL to change the type of a column
1:13 but it has data in it, so you have to like transform, like— what do I do. This is the kind of stuff you do right here, so here's the script
1:20 and I could hit just boom, execute it and it will modify the database or I could say just open this here in this editor
1:28 and I could make these changes and when I'm ready, I push this button and run it, and then I make the changes,
1:33 let's go over here comment that out and run this, alter table, one row is affected that sounds like something happened
1:42 and let's go resync, oh there is a rating, that's an integer, I don't like it anymore, we'll go over here and we can just remove it.
1:54 Alright, so we're going to begin a transaction drop a bunch of stuff, recreate it, that's pretty intense
1:58 but if we do that now our rating is gone again, so this modifying data— not the simplest thing to do in relational databases,
2:06 like I said at the start, I think this is one of the harder parts to evolve your database especially once it has data in it,
2:12 but, not too bad with the tools we have at hand here.


Talk Python's Mastodon Michael Kennedy's Mastodon