Introduction
Text information
Boolean
Date and time
Summary

Instruction

Okay! As you can see, the database didn't let you enter a value which was longer than the maximum. Quite understandable, isn't it? The type varchar(x) lets you provide any value which is shorter than or equal x.

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

When do we use it? Consider the vehicle identification number (VIN). Its length is fixed - it is always 17 characters long. That makes a perfect candidate for 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: with one column named first_name (up to 32 characters) and another column named nickname (exactly 10 characters).

Stuck? Here's a hint!

Type

CREATE TABLE user_account (
    first_name varchar(32),
    nickname char(10)
);

Console

Code editor

Result

TableConsole