Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Your first table
Text data types
Summary

Instruction

So, the database didn't let you enter a value that's longer than the limit defined for that field. Quite understandable, isn't it? The type varchar(x) lets you provide any value which is shorter than or equal to x.

There is also another text type called char. The difference is that char stores fixed-size information. For instance, varchar(10) lets you add any value of up to 10 characters, whereas char(10) expects you to have exactly 10 characters every time.

When do we use the char type? Consider the vehicle identification number (VIN). Its length is fixed – it is always 17 characters long. That makes it a perfect candidate for the char(17) data type.

Exercise

Peter decided to experiment with the nicknames a little bit. He now wants every user to have a nickname which is exactly 10 characters long.

Create the table user_account from scratch. This time, have one column named first_name (up to 32 characters) and another column named nickname (exactly 10 characters).