Appendix D. Using SQL Datatypes

As explained in Lesson 1, “Understanding SQL,” datatypes are essentially rules that define what data may be stored in a column and how that data is actually stored.

Datatypes are used for several reasons:

• Datatypes enable you to restrict the type of data that can be stored in a column. For example, a numeric datatype column will only accept numeric values.

• Datatypes allow for more efficient storage, internally. Numbers and date time values can be stored in a more condensed format than text strings.

• Datatypes allow for alternate sorting orders. If everything is treated as strings, 1 comes before 10, which comes before 2. (Strings are sorted in dictionary sequence, one character at a time starting from the ...

Get Sams Teach Yourself SQL in 10 Minutes, Fourth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.