Types of Data2:45 with Andrew Chalkley
There are good reasons why your data should be categorized in to different types. In this video we'll explore some of them.
Types of Data
Here's a slightly larger list of data types than in the video.
- Text Type Examples
- Numeric Type Examples
- Date Type Examples
Here's documentation sites for some other databases where you can see the similarities and differences in data types.
Table columns are defined in the schema to have certain data types. 0:00 A data type describes the value to be stored. 0:04 There are several data types you'll come across on a regular basis. 0:08 There are text types, numeric types and data types. 0:11 Text types are good for storing names or descriptions of things. 0:15 Numeric types are good for storing prices, ages, and quantities of things. 0:20 Dates are good for anything time related. 0:26 While this isn't a comprehensive list of data types, text, numeric, and 0:30 date types are a good starting point. 0:34 The reason we use types will become more important as we write SQL later on. 0:37 To help you envisage how its schema enforces types and 0:42 columns, you can think of the schema as a coin sorter. 0:46 A coin sorter is used to sort different types of coins into columns. 0:50 The coin sorter ensures that only the correct coin types go 0:54 into the correct column. 0:58 Like the coin sorter, 0:59 the database schema prescribes what data should go into each column of the table. 1:00 You may be asking, why even do this? 1:06 Let's look at some examples to see why it's important to have data types. 1:08 Imagine everything in this product table was just text. 1:13 The name, price, stock count, are all text. 1:17 If I wanted to sort by the current stock count, what result do you think I'd get? 1:21 Well, it'd be sorted like this. 1:26 This is because the stock count is sorted alphabetically, and not numerically. 1:29 Let's change the price and the stock count to a numeric type and 1:34 sort by stock count again. 1:38 That looks better. 1:40 Having correct data types in your database not only helps with sorting but 1:42 it also comes in handy for 1:46 many other applications such as generating the sum of all sales figures. 1:48 Generating a sum and 1:53 other mathematical operations can only be done by using with a numeric type. 1:54 Trying to do math with text is impossible. 2:00 In the case of an events table for an event planner where the new data is added 2:04 all the time, the data is retrieved in the order it was entered by default. 2:08 If the date of the event column was just text and 2:14 you attempted to sort it, it would look like this. 2:16 However if the date of the event was correctly at date type, 2:20 it would sort like this. 2:24 Understanding that column date types can affect how data is retrieved 2:27 helps people design the schema for the database. 2:32 While we're not designing the schema ourselves in this course, 2:35 understanding data types will also help us understand 2:38 how we compose the SQL queries throughout this course. 2:42
You need to sign up for Treehouse in order to download course files.Sign up