1. Data
Welcome to the final part of the databases chapter where we'll learn about database storage and data types.
2. Database storage
Now that we know what a database is, we have to think about where it is housed.
All this data in our databases must be stored somewhere, right?
Data is stored on a server's hard disk. Servers are powerful computers that store information and perform services via requests made over a network. In our case, the service performed is data access.
Servers can handle a large number of data requests simultaneously, making them ideal for collaboration.
3. SQL data types
When creating a table, we name each field and decide what type of data will be stored in it.
The data type depends on the specific information stored in the field, such as numbers, text, or dates. We also want to consider the type of operations that we want to apply to that information.
For example, it is logical to multiply numbers together, but multiplying someone's name does not make sense.
4. Strings
A "string" is a sequence of characters such as letters, numbers, or punctuation.
In the patrons table, the data in the name field is made up of strings, such as "Maham" and "James".
SQL has several different data types that can hold strings. The VARCHAR data type is commonly used due to its flexibility to store small or large strings.
5. Integers
Integer data types store whole numbers, such as the numbers in the card_num field of the checkouts table.
INT, a common SQL integer data type, can store numbers from less than negative two billion to more than positive two billion!
6. Floats
In addition to whole numbers, we also have numbers that include a fractional part or a decimal point, such as the $2.05 that one patron, Jasmin, owes in fines. In programming, these numbers are referred to as floats.
The NUMERIC data type can store floats with up to 38 digits total, including those before and after the decimal point.
7. Schemas
Now that we're familiar with data types, we can look at a database schema.
Schemas are often referred to as "blueprints" of databases.
A schema shows a database's design, such as what tables are included, any relationships between its tables, and what data type each field can hold.
The schema for our library database shows the VARCHAR data type is used for strings like book title, author, and genre. We can also see that the patrons table is related to the checkouts table, but not the books table.
8. Let's practice!
Okay, let's get some practice with data!