Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Your First Table
CREATE TABLE basics
6. How tables work – continued
Entity Relationship Diagrams (ERD)
Summary

Instruction

Good. Now, let's explore table structures more deeply. Each column stores a certain type of data. Some columns store numbers (price, quantity, id), while other columns store text (names, descriptions) or dates.

Why do we need to specify data types for columns? Couldn't there be one general data type for everything? Well, internally, our database performs a lot of bookkeeping. It needs to know how much space it should have for the data in a given column. For example, a longer text requires more space than a short number.

What's more is that the database has many additional structures that make it run faster, such as row sorting. And numbers are sorted differently than text. This is why we need to specify column types each time we add a column to a table.

Exercise

Let's experiment with data types a little bit. In our table exhibit, there is a column id that contains the identification number of the toy. The data type has been chosen to only allow number values, so let's try to insert a row with some text in that column and see what happens.