MySQL 25 - CHAR Data Type

submitted by mkenny400 on 03/20/18 1

The first category of data types that we are going to cover in this MySQL series are the string data types, or character data types. There are two that I am going to talk about in this video, CHAR and VARCHAR. We'll start with CHAR. CHAR is a string data type where you specify how many characters are allowed in parenthesis after you declare the column as this type. For example, we can say CHAR(50) to allow up to 50 characters for each value in that column. The thing to know about CHAR though is that it is a fixed-length string. That means every single value inside of that column is actually going to be whatever you declare the length as. So if you say CHAR(50), every string is going to be 50 characters long. If, for example, you have a row that only uses 40 characters, MySQL will pad the right side of the string with spaces until it fills 50 characters. Now, the highest value you can put in here is 255. The 255 refers to characters. This means that you can have strings with up to 255 characters. How does the computer know how to store these characters? That has to deal with the character set and the encoding of the characters. By default, MySQL is going to use UTF-8. We are not going to discuss UTF-8 in detail for a while but essentially UTF-8 says that each character can take up to 3 bytes of storage. 255 comes from the max number you can count to using binary. So if we are keeping track of how many values are in this column in an 8 bit number, 255 is the highest. If you don't know what I'm talking about it, we'll worry about it later. You can actually make the column CHAR(0). In this situation, the only thing you could put in as a value for this column is an empty string (''). When retrieving variable length CHAR data from a database it may not look like the database pads the value. That's because MySQL actually strips spaces from the value when presented. If you want to keep all of the spaces that have been added when you retrieve the value, you can do that. Look up PAD_CHAR_TO_FULL_LENGTH online. In the next video we are going to discuss VARCHAR. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Support me! www.patreon.com/calebcurry Subscribe to my newsletter: eepurl.com/-8qtH Donate!: bit.ly/DonateCTVM2. ~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~ More content: CalebCurry.com Facebook: www.facebook.com/CalebTheVideoMaker Google+: plus.google.com/+CalebTheVideoMaker2 Twitter: twitter.com/calebCurry Amazing Web Hosting - www.dreamhost.com/r.cgi?1487063 (The best web hosting for a cheap price!)

Leave a comment

Be the first to comment

Collections with this video
Email
Message
×
Embed video on a website or blog
Width
px
Height
px
×
Join Huzzaz
Start collecting all your favorite videos
×
Log in
Join Huzzaz

facebook login
×
Retrieve username and password
Name
Enter your email address to retrieve your username and password
(Check your spam folder if you don't find it in your inbox)

×