Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How important is it to select the smallest possible data type when designing a database?

How much of a difference does using tinyint or smallint (when applicable) instead of just int do? Or restricting a char field to the minimum characters needed?

Do these choices affect performance or just allocated space?

like image 372
Matteo Riva Avatar asked Jan 31 '10 16:01

Matteo Riva


People also ask

Why is it important to identify data types of our database?

A data type determines the type of data that can be stored in a database table column. When you create a table, you must decide on the data type to be used for the column definitions. You can also use data types to define variables and store procedure input and output parameters.

Why is it important to choose the correct data type when doing the physical design for a database?

Choosing the right data types when you're designing your columns, tables, and indexes is really critical. Using the wrong data type can cause more space to be required, affecting data density in memory, database and backup size, transaction log efficiency, and more.

Why is it important to define the data type of a field when designing a relational database?

A data type tells the database what functions can be performed with the data. The second important reason to define the data type is so that the proper amount of storage space is allocated for the data.

Which data type has smallest data size?

The smallest data type is a byte, which is 8 bits. Each bit can be a 0 or 1.


1 Answers

On an Indexed field with a significantly large table the size of your field can make a large affect on performance. On a nonindexed field its not nearly as important bit it still has to write the extra data.

That said, the downtime of a resize of a large table can be several minutes or several hours even, so don't make them smaller than you'd imagine ever needing.

like image 163
MindStalker Avatar answered Oct 12 '22 23:10

MindStalker