Locked lesson.
About this lesson
Quick reference
Working With Data Types
Each Column has to have a name and a Data Type.
When to use
Whenever you build a database table, you need to work with Data Types.
Instructions
Data Types let the database know what type of data will appear in the column.
Each type of database has it's own data types. So you should always look them up before designing your database.
There are many different types of data and every database handles data slightly differently. Anytime you design a database, you will need to look up the data types for that particular server.
Some of the data types we will use in this course are:
- int - a number without decimals
- varchar - variable length character strings
- text - variable length character strings, but not a recommended data type as it has limitations when searching and indexing
Hints & tips
- All columns need a name and a data type
- The most common are Varchar and Int
- 00:05 In this video, I wanna talk about Data Types.
- 00:07 So we've got our database, we've got our table, we've got our columns and rows.
- 00:10 Now, each column has to have a name, it also has to have a data type.
- 00:14 And a data type tells us what kind of data we have,
- 00:18 what is the type of data, data type.
- 00:20 For instance, we can add another column here, let's call it Age and 39.
- 00:24 So, 39 is a number and we have to, when we design our database,
- 00:28 when we set this up at the beginning we have to tell our database what kind of
- 00:33 data we expect in each field, right?
- 00:35 So in our Age field, we know this is gonna be a number, so
- 00:38 we're gonna tell it hey, it's gonna be a number.
- 00:41 Well, you have to know the types of data, it's just not a number,
- 00:44 in this case it would be an integer.
- 00:46 So, those different names and
- 00:47 those different types of data are what we're gonna talk about in this video.
- 00:51 So we have text in some of these, we have numbers in this one,
- 00:54 we have both numbers and text in this field right here, in this column.
- 00:59 So what's going on here?
- 00:59 So, in the world of database, there are many different types of data that we can
- 01:04 use and each type of database categorizes them slightly differently.
- 01:08 MySQL uses certain types of data or numbers.
- 01:12 SQL Server calls it something slightly different.
- 01:15 Every database handles data types differently.
- 01:17 So, my point is don't try and memorize this, because you can't.
- 01:21 If you switch from different servers, you're not gonna remember, SQL refers to
- 01:25 integers as integers, Postgres refers to them as floats, and on and on and on.
- 01:30 So, anytime you design a database, the first thing you wanna do is just look up
- 01:34 the different types of data for that specific server.
- 01:37 So we just go to Google, and in this course, we're gonna be using SQL Server,
- 01:41 Microsoft SQL Server.
- 01:42 So I would just type in something like, SQL Server database data types.
- 01:46 And you're gonna see all kinds of stuff.
- 01:49 There's the official one for Microsoft, that's a good one.
- 01:51 TutorialsPoint, they always have good ones.
- 01:53 So I'll just pull this one up and we'll look at this real quick.
- 01:56 There's not enough time for us to go into all of these in great detail but
- 01:59 you can see SQL Server offers six categories.
- 02:01 Actually they're seven, there's a miscellaneous one at the end.
- 02:04 But, they're broken into six main categories.
- 02:07 We have exact, number types, and in this one we're mainly gonna be using this int,
- 02:11 I-N-T which stands for integer.
- 02:13 Which is basically just a whole number without decimal point,
- 02:16 approximate number types, and I'll talk about these in just a second.
- 02:19 Date and Time, Character Strings, that's basically text.
- 02:23 And here are the main ones we're gonna be using are varchar and text.
- 02:26 Text, we'll use this,
- 02:28 it has a lot of limitations that we'll see as we go through the course.
- 02:31 Varchar stands for
- 02:32 Variable Characters and it's just strings of characters of different lengths.
- 02:37 And, you see there's max on here, you can designate exactly what length you want or
- 02:41 you just leave that off and it will just do the max.
- 02:44 A Unicode Character String, it's basically text but for Unicode.
- 02:48 And that deals a lot with different languages,
- 02:51 they might have slightly different alphabets.
- 02:54 Unicode deals with those types of things.
- 02:56 Binary Data Types, yes or no, true, false, that sort of thing.
- 03:00 And then we have Miscellaneous Data Types, timestamps, and XML,
- 03:03 and different things like that.
- 03:05 So you're not usually gonna use a lot of these miscellaneous.
- 03:09 You're not gonna use a lot of these, any of these.
- 03:11 The big ones you're gonna look at are character strings and numbers.
- 03:16 So if you know you're, back in the day, computer processing power was
- 03:20 not very big, and there was not a lot of storage on computers.
- 03:24 So every time you could keep your data as small as possible and
- 03:28 we could tell our database, only accept numbers with two digits.
- 03:33 Well, for that, we know the exact data type, it's a two digit number, right?
- 03:38 We can specify exactly how many bits and bytes and things.
- 03:41 These days it's not all that important, so personally I just use,
- 03:45 sort of approximate numbers and also approximate character strings.
- 03:49 I don't generally tell my databases to expect words of seven characters for
- 03:55 each column or whatever.
- 03:57 You'll learn more about this stuff as we go, but these are basic,
- 04:01 take a few minutes and look through these and Google a couple of different ones,
- 04:05 maybe read the Microsoft Docs.
- 04:07 And as we start to use SQL Server, you'll see these in action, and
- 04:10 then they'll make a lot of sense.
- 04:11 It's just a matter of saying, this is gonna be an integer,
- 04:14 this is gonna be text, this is gonna be a character, stuff like that.
- 04:17 So, that is data types, and
- 04:19 it's sort of the last important thing to understand about databases.
- 04:23 So databases have tables, columns, and rows.
- 04:25 In each of those columns, we have data of certain types, and
- 04:29 each column can only have a certain type of data.
- 04:32 So in the Age column, we would only put numbers, right?
- 04:35 We will not put John in an Age column because John is not a number.
- 04:39 So, just common sense, right?
- 04:41 So, that's Data Types.
- 04:43 In the next video, we'll start setting up Microsoft SQL Server 2016.
- 04:47 It's gonna be a lot of fun, and that's all for this video.
Lesson notes are only available for subscribers.