Understanding SQL Data Types: Strings, Integers, and Floats Explained

SQL data types like VARCHAR for text, INT for whole numbers, and FLOAT for decimals determine how information is stored and what operations you can perform. A schema is the blueprint showing your tables, their fields, and how they connect. Everything lives on a server's hard disk.
Chapters
Welcome to the final part of the Databases chapter. This lesson will focus on the data inside a database as well as its storage. When a table is created, a data type must be indicated for each field. The data type is chosen based on the type of data that the field will hold. A number, text, or a date, for example. We use data types for several reasons. First, different types of data are stored differently and take up different amounts of storage space. Second, some operations only apply to certain data types. It makes sense to multiply a number by another number, but it does not make sense to multiply text by other text. For example, in programming, a string refers to a sequence of characters, such as letters or punctuation. On the Patrons table, the data in the Names field is made up of strings, such as Maham and James. SQL has several different data types that can hold strings. Some string data types can only hold short strings, such as a string up to 250 characters. Storing short strings in a small data type like this saves storage space. SQL's Varchar data type is more flexible and can store small or large strings up to tens of thousands of characters. Because of its flexibility, varchar is very commonly used for storing strings. Integer data types store whole numbers, such as the years in the member year column of the Patrons table. Just as with strings, SQL offers a few different data types for storing integers, depending on how big the numbers we'd like to store are. Int a common SQL integer data type can store numbers from less than negative 2 billion to more than positive 2 billion. Float data types store numbers that include a fractional part, such as the 2.$05 that one patron Yasmin owes in fines. Just as we might expect, SQL also offers several float data types, depending on how many digits the numbers in the field are expected to be. The numeric data type can store floats which have up to 38 digits total, including those before and after the decimal point. 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 in the database, and any relationships between its tables. A schema also lets the reader know 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. Finally, let's discuss storage. The information we find in a database table is physically stored on the hard disk of a server. Servers are centralized computers that perform services via requests made over a network. In our case, the service performed is data access, but servers are also used to access websites or files stored on a server. Any computer can be a server if it is set up to provide a service, even a laptop. However, servers are generally very powerful and large machines because they are best equipped to handle a high volume of requests and data.
More from Richie

#359 My Best Friend is AI with Valerie Tiberius, Professor of Philosophy at University of Minnesota

How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon

#358 How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon







