So merchants can have many countries, countries can have many merchants and their respective country codes, et cetera. And there's some other reference points in here also. So this is a great tool and we're gonna be using it to build out our initial schema.
So let's do that. I'm gonna just click on the dropdown and click on new diagram. And then over here, I'm going to start my first table like this. And I'm just gonna call it source, open close brace. And then let's see if we'll go ID UUID. So a UUID is a 16 bit integer value. It looks, usually it's represented with dashes in it to make it a little bit more readable. Every database has it. It's one way to ensure that your ID is unique. And unlike the auto increment where you can run into conflicts because it will go one, two, three, four, five, and then if more than one person is trying to insert something, you may run into a conflict where somehow they get the five and then five gets overwritten, or five gets deleted, and then someone else tries to add it and there might be a collision between those because they're not particularly unique numbers. A UUID, however, if you use a UUID generator, which every database has a function or something that will allow you to create it automatically. And most codebases, whether you're using JavaScript or Python or whatever, there's something that will enable you to create a UUID. So you can insert without worry of conflict and you can reference without worry of running into, needing to deduplicate if for some reason like somebody turns off the key around the UUID that keeps it unique. So in this case, I'm gonna start off right off the bat, setting this UUID as the primary key, P-K-A. Then I'm gonna add a date stamp. So there's often, and this is something very important to data modeling. It's a good idea to have a default set of columns that are basically duplicate across all tables that offer you audit capabilities. Especially when working in the enterprise environment where audits happen on a semi-regular basis, it's always great to have certain things that the audit will require, such as timestamp to represent when the data was last changed and other pertinent information that may be required by the audit. Like the user who made the last change. And it gives a path, a trail that the audit can be done on so that you know all of the things that have changed or altered or manipulated the data in any way throughout the database. Some of the default things that I always add is timestamp and often, I'll put in the system user, not particularly the database user, but the system user. Because a lot of the time the database system will keep track of the user that's changing the data anyway. So if you wanna make it easy to be queryable in the tables themselves, you wanna add a timestamp, you wanna add a user, maybe the system user or the database user depending on whatever your requirements are. So in this case, I'm just keeping it simple and I'm just gonna have the timestamp, not gonna get into the users and everything. So that's what that is for. And again, the database has a function which we can use to have it timestamp it, it puts the timestamp stamp in the column. So we don't have to like manually enter that or derive it from code or anything like that. It can be overridden, but the database can do it for us too. I think I answered the UUID question, Pravin. So if you have any other questions about that, feel free to ask and I will get into that more. And we'll also look at an example. So beyond just talking about this, you'll see the database generate one when we enter some data into the database shortly. All right, so the next thing in source, I wanna do name, so put text and then URI. So like the name of the source, I'm thinking of this table as something that provides sources of where data is at or a reference to data, where data is at. Think of it as something where you had to look up in a dictionary or in a library or something like that, but in this case, you know, it's the internet, you've looked it up on the internet and you want the URI, so the actual location of the universal resource indicator, and you want a name to be able to give it a friendly name that us humans can read and understand what it is, and then finally, I'm gonna add a details, and details will basically be something like just notes that we might keep about a particular source that we've collected for some reason. Like if I find an awesome page on GraphQL and React or something like that, I'd put the URI in there, add a friendly name, and then add more details about what it is specifically. So basically a very glorified table of bookmarks.
Then let's add one for source notes like this, and I'll add a source ID. So that source ID, the reason I named it that, because it's not the ID of the table. It's the ID that references back to another table that this table will be related to. So I'll do a UUID because it needs to be the same as the table that it references back to, and then I'm gonna add a reference. An NDB diagram, that's ref colon chevron, the name of the table that it's related back to,.id, the column that it's related to. So there's that, and the details text, and then stamp, I'm gonna have time stamp for this table too There was a question by Nebertec, what is faster, UUID or auto increment? If you're talking about a large volume of data being inserted, you're gonna win out with UID's, UUID's, and I'll tell you a reason. If you have one system, only one system, with just that one systems throughput writing inserts to a database with auto increments, it can be pretty fast, and auto increments can be fast in all sense of reality. However, often if you have a lot of inserts, you also have a lot of clients trying to do the inserts. They're going to get very slow with auto increments because they are gonna run into collisions, and they're gonna have other conflicts come up as you work through these inserts.
Comments