课程: Programming Foundations: Databases
Relational databases
- There's more than one type of database out there. Graph databases like Neo4j, object databases like Realm and Objectivity/DB, document databases like CouchDB and MongoDB and more. But by far, the most common is the relational database, which is named for the way that it organizes data into relations or tables of related data. In a relational database, tables are made up of rows, which represent instances of a given entity, and columns, which represent attributes of each entity. The set of columns is called a relation. Let's explore what that actually means. Let's say we have a restaurant, and have a table in a database that keeps track of a list of customers. Here, customers are the entity. We're talking about different customers but they all share the condition of being a customer, and each individual customer is an instance of a customer. This one is different from this one, who's different from that one, but they all share in being customers. As customers, they also all share certain attributes or things that describe them in particular. They all have names, for example, and email addresses, and phone numbers, but their individual names, emails, and phone numbers are different from each of the others, even though they sure these attributes in common. If we have another table, say a listing of dishes offered by the restaurant, dishes are the entity. Each dish is an instance, and each dish has particular attributes, like a name, a price, a description, and so on. These dishes and customers are kept in separate tables in the database, because they're different entities. Dishes don't have phone numbers, and people don't have prices. So a relational database is made up of relations or tables which are the set of columns, and these tables also contain rows, representing different instances. Every column or piece of information about the individual instance will have a type that we define to tell the database what sort of information it contains. That might be a number or a string of text. It could be a date, a true or false value or even a chunk of binary data that represents a file. All the values in a specific column will be the same kind of information, though the individual values will vary. In this chapter, we'll explore the general properties of relational databases and get into details later on.