- Read Tutorial
- Watch Guide Video
In this guide, we're going to talk about diagram modeling and specifically, we're going to talk about our diagrams and the way that you can generate those is if you hit command + r that is going to bring up the reverse engineer database dialog box. And also if you go up to the drop-down where it says database you can also access it.
Here you pick out the connection that you want to use for this. I'm going to use the dev camp course and nothing else is going to change. Hit it continue, it's going to connect, and then it's going to give me access to the databases. So I'm going to click on the database that we actually want and continue. It's going to check everything and assuming that everything here works I can continue and then hit execute. Now when this is all done it's going to just give me a little report. Hit close and you can see here is our modeled table. Now, this is pretty neat. So easy.
Our diagram is essentially a way of modeling in a visual format how you can structure your database so right here you can see each one of our tables is here. They're the exact same way as if we access them on the command line or if we access them in bicycle workbench this is just a different view.
So that's one very important thing to keep in mind. Nothing magical is happening here. This is just a different way of looking at it. If you are familiar with UML modeling this is very similar to the way UML works that just this one specific just a database tables. The reason why I wanted to show you this and because also something that I think can be very practical is if you only have three or four tables it's really not a big deal.
You should be able to kind of just look at all of them and then you can click on them and see how they are wired up and how they're connected. However, if you're working with a giant database that's very difficult to do it's very hard to see where everything is connected and how the relationships work.
And so what this is going to allow you to do is to be able to pick and choose the different things that you want to see. So if I want to look at addresses here I want to know exactly how do all of these work. So how exactly is an address connected to users?
So I can see OK the relationship is on this address is user user's ID this is a foreign key and you can see these little arrows points up to the users model or to the users table. And then this gives you access to be able to see each one of the parameters that give you the data type that's being used and also another nice thing.
It shows you all of your indexes right here. So if you click on this all arrow shows you each one of the indexes if you remember back when we talked about indices right here we can see that I created that postal code one is now listed right here and my list of indexes guides same thing is our primary.
And then also our foreign key. Now notice with the ugly table that we talked about in database normalization this has no connection to any other table so it's still here. It's in our schema so it's still all of the database tables are going to be in here but it's not connected things. That's a reason why you don't have this mapping.
So this gives you a really nice and easy way of being able to see how every component in the database how every table is mapped and being able to see the parameters that are used. And if you're a visual person this can come in really handy. And this is a great way of being able to see how all of this works. Now also if you really want to dive into it you can look on the left-hand side here and you can see that it even kind of explains what some of these relationships focus on.
So here we have a one to end relationship so this is the type of situation that we have going here where we have a user that has many addresses a user that has many guides and so that's how you can tell with this little arrow or the triangle pointing out it goes and it ends at the Users table that tells us that a guide belongs to a user just like an address belongs to a user as well.
And so there are other things you can do you can actually if you prefer instead of doing it the way that we did it throughout this course where you just go in the dialog box and type in your other parameters you could technically build your entire system just here in the E.R. diagram. It's perfectly fine to do that. I personally I'm not a huge fan of doing that just because that's not the way that I learned it.
And so I by default usually will do it just at the command line or if I'm using a tool like my sickle workbenches I'll just use one of the dialogue systems and type those in. But if you like visual things I definitely recommend for you to play with this. Test it out. Change values change data types set up relationships set up your foreign keys.
All right here and it's going to maybe give you some flexibility or maybe it maybe you'd enjoy doing this more. So that's also a very important thing. It's very important to be able to love the tools that you use. And so if you like visual type tools then this may be a good fit for you but that is an introduction to our diagrams in SQL.