Free Relational Database Tutorial and Tips For Beginners!
Intro To Data Modeling
How many files do I need to create?
Actually, each situation requires a different number of files. Sometimes one file, sometimes 300 or more. Here's an oversimplified way to design your files.
First, gather all information regarding your project. Let's say, you're creating a computer system to run a college. Get the college info (name of college, building locations, class room locations, etc., address, phone numbers, etc.), all info kept regarding students (not the actual data for every student, but the types of info in general, for example, take note that the college maintains this info: student name, student address, student date of birth, etc.), professor information, student course info (subject taken, semester taken, professor name, etc.).
Collect a sample of each type of info, for example, student report card, professor schedule, any and all documents, existing computer files, etc.
Okay, now you have giant pile of every piece of info regarding the college. Next step, is figuring out what the entities are. An oversimplified way of describing what entities are is to say that they can be a person, place or thing. Here's what some of the entities would be for our college example. The college, the students, the professors, the buildings, student grades, courses, course schedule, etc. Separate out all of the entities.
Next step, find all of the properties of the entities and list them under the entities. For example, student address is a property of student entity. Here's more examples:
So we started out with this giant pile of information, and now we're picking up each piece from the big pile and dropping them in little entity piles where they belong, until the big pile is gone. How about the course schedule? What properties would that have? Well, we can see that the course schedule entity, is an intersection file like in the library example.
Here's what the course schedule would look like:
Notice, like in the library example, that you don't have to redundantly type in lots of information in the course schedule file to uniquely identify a specific class. For example, you don't have to type in the course description over and over again, because the software pulls that from the course file! The course unique id is enough to let you know exactly which course it is and the software connects the two files when you need to see all of the info! Also, you don't have to type in the professor's name over and over again, as that is pulled from the professor file. Just the professors' social security numbers are all that are required in the course schedule file.
You may need many intersection files. For example, the grades file would be another intersection file.
For the grades file, notice that you don't have to type in the student's name or address over and over again. Same with the the course; just unique course id is enough so you don't have to type in the course description over and over again thousands of times for each student taking it! You only need to type in the course description once, in the course file. The software will pull the course description in and merge it with the grades and display it on a computer screen or printout when someone wants to see it.
Looking at data modeling like this, its possible to develop an intuitive feel for setting up your files with the goal of removing unnecessary redundancy. Anybody can get this! Just remember that one of the properties for each file must uniquely identify each instance of the entity. For example, the professor file absolutely must contain some property that uniquely identifies each professor, e.g., social security number. Same with the building file, it absolutely must contain a property that uniquely identifies it from all other buildings in the college, e.g., building name. This is called putting the data in third normal form, which you can study more formally in the books on the side bars.
The software connects the various files by matching keys or other fields. E.g., it will match professor social security number from the course schedule file with the social security number for the professor in the professor file. For each use that you want to make of the data, you find the files that contain your information and merge it onto your computer screen or paper printout. This merge is called a "join". The join doesn't create permanent new files, it just temporarily matches the information from the various files that you're interested in and displays them on your computer screen or paper printout.
Here's an example: the dean wants a printed report of every classroom in the college with its street address. You don't need the student or professor files for this. Here's two files that you would need:
There is a right way and a wrong way to design files. Notice that you do not want to have a "street address" field in the classroom file because that can already be derived from the building file. If you put the street address field in the classroom file, you would be unnecessarily repeating the street address over and over again. You know which building the classroom is in, and the building file has the street address in it. Are you feeling your intuition working yet? You will. Once you start seeing actual examples of your experiments, let's say the street address is repeated hundreds of times in the class room file, then you kind of start seeing that the street address really belongs in the building file. When designing your files, put some actual data in them and look for high repetitions of the same information. See if your intuition is telling you that maybe a field in one file doesn't belong there but really belongs in another file.
Continuing on with the task that the dean has assigned you, you would "join" both files, matching them by the building name, which is a property of both files. Building name is the key to the records of the building file. The result would look like this:
But the above would not be another file. Its just derived from the other files and displayed on the computer screen or paper printout at the time the viewer wants to see it.
Don't create unnecessary files (for example, a file that looks like the one above) if the information can be derived from the already existing files.
Sometimes the key of a record is made up of more than one field (property). For example, in the course schedule file above, you can't uniquely identify the schedule for a specific course without including course unique id, semester, classroom location, class time. Think about it, the exact same class could be given 3 or 4 times in the same classroom, so you absolutely need to include the time that the class meets to distinguish it from the same course being taught in the same room but at another time.
When designing your data files, notice that they do not look like the paper documents in the college! For example, the course schedule has a lot of info trimmed off compared to the paper printout version because it can derive what it doesn't have from the related course, building and professor files. This confuses a lot of beginners but, you get used to designing the data files like this. The intersection files have just the bare minimum required to uniquely identify the entities that they will be pulling the rest of the info from.
When designing files, get rid of unnecessary redundancy! Some redundancy is necessary though, for example in the course schedule file, the semester that the courses are taught in will have to be repeated over and over again, to make sure that students and professors know which semester each class will be held in. We're talking about getting rid of unnecessary redundancy, not necessary redundancy.
When creating reports from your college database, you may want to know how to retrieve only certain records that you are searching for. To solve this problem, software languages have been invented to manipulate and retrieve data selectively. SQL (Structured Query Language) is one such language. In essence, using a software language, you can frame questions to your system of files that you have designed, like this: "Please match all of the course, and course schedule records, and all of the professor records using the "professor social security number" and "unique course id" to match them with, then list only those courses in the sociology department this semester."
In general, you first model your data, design your files so that each entity has a unique key and then add the rest of the fields that are attributes of that entity. Then the rest is easy, just create desired reports from your data by joining your files. This means matching the keys from relevant files with the matching fields in the related files. You'll be amazed how very complicated problems can be easily solved using relational databases.
In real life, we don't want to use social security number as a person's unique ID any more because of the growing problem of identity theft. Instead, you, or often the computer program, can make up a unique ID number for each person in your database.
Got suggestions on how to clarify or improve this? Send me an e-mail!