From the course: Programming Foundations: Databases

Understanding databases: Benefits of structured data

From the course: Programming Foundations: Databases

Start my 1-month free trial

Understanding databases: Benefits of structured data

- We've solved one of the problems we had with the cards, being able to use the customer data more efficiently, but we still need to track which customer has ordered which dishes and how many times. Of course, you can sort of shove the information into this spreadsheet and record what each customer has ordered either all crammed into one field or by adding one field for each visit, but this will quickly run up against problems similar to the notecards. If you want to know what a customer has ordered, you'll need to dig through those fields and count sandwiches, or salads, or bowls of pasta each time and you'll need to add data without accidentally removing what's there or you'll need to keep adding fields. We've reached another limitation and it's in overcoming this limitation where databases become even more helpful. If we think about all those meal orders are their own cards, we can take their information and create another set of rows and columns. These collections of rows and columns are called tables and they're the building blocks of databases. Generally, columns contain just one piece of information. So commonly we'll split values like Full Names into separate columns so we can use each piece of data they provide separately. And some values, like dates, will be recorded in a slightly different way to accommodate the format that a database expects. A database can contain more than one table and databases offer the ability to create relationships between tables based on rules you define. We'll see more about this in detail later on. The structure of tables in the database is called the schema. If we start to add a little more information to our Customers and Orders tables, like a unique identifier for each row, now we can connect our orders to our customers and easily find out which dishes a customer has ordered. Aside from providing structure for our data, a database allows us to enforce certain rules on our data too. We can ensure that certain data isn't missing or that a field or column contains only a specific type of data. We can protect data from unauthorized access or changes and we can make sure that a change only gets made if other associated changes are made successfully. As we move on, we'll look at how all of these pieces work in more depth, but here we've seen how adding structure to data can help us answer questions and why we might choose a database instead of just a spreadsheet.

Contents