WHY CAN'T EVERYTHING BE TEXT?

RDBMSs were created to store information, and human readable information comes in letters and numbers. You might have heard that computers use nothing but ones and zeroes to represent information. These are the numbers, and they are used to represent letters. So far, so good. What about dates? The date 10112010 would be October 11, 2010 in the United States. For most of Europe it would be November 10, 2010; in China the first four digits might be interpreted as 1011. What about pictures? There are massive amounts of ones and zeroes packed according to specific file formats: JPEG, PNG, BMP, and TIFF, to name a few. How about sounds? I am sure you've heard about WAV and MP3 files. Video? AVI, MPEG, and so on.

To computers, they are all ones and zeroes, but humans need more than that. Humans are programmed (no pun intended!) to deal with different types of information. We “intuitively” can tell an image from a time, a date from text, and sound from a number, so we created computers in our own image and programmed them to treat data types differently.

images There is an historical reason for introducing data types to SQL: a dearth of storage space. Some of you might remember the millennium scare, where havoc was to occur because the year was represented by two digits instead of four. By the same token, if the numbers were presented as numbers in binary system, ...

Get Discovering SQL: A Hands-On Guide for Beginners now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.