You are on page 1of 4

Field Data Types

Once you have identified the tables and the fields for your database, the next step is to determine each fields data type. With any relational database management system, you need to define what kind of information each field will contain. In most relational database management systems, there are three primary categories of field types: 1. Text 2. Numbers 3. Dates and Times Within each of these primary categories, there are variations of these categories, some of which may be specific to individual RDMSs. I will highlight particular differences as they arise. It is important to give careful thought and consideration to field types because they dictate what information can be stored and how it is stored which may affect database performance.

MySQL Data Types


Below is a list of data types for MySQL (adapted from Ullman L. MySQL. A visual quickstart guide. Peachpit Press: Berkeley. 2003.): Note: The square brackets [] indicate an optional parameter to be put in parentheses, while parentheses () indicate required arguments. Type CHAR[Length] VARCHAR(Length) TINYTEXT TEXT MEDIUMTEXT LONGTEXT TINYINT[Length] SMALLINT[Length] MEDIUMINT[Length] Size Length bytes String length + 1 bytes String length + 1 bytes String length + 2 bytes String length + 3 bytes String length + 4 bytes 1 byte 2 bytes 3 bytes Description A fixed-length field from 0 to 255 characters long. A fixed-length field from 0 to 255 characters long. A string with a maximum length of 255 characters A string with a maximum length of 65,535 characters. A string with a maximum length of 16,777,215 characters. A string with a maximum length of 4,294,967,295 characters. Range of -128 to 127 or 0 to 255 unsigned. Range of -32,768 to 32,767 or 0 to 65,535 unsigned. Range of -8,388,608 to 8,388,607 or 0 to 16,777,215 unsigned

INT[Length] BIGINT[Length] FLOAT DOUBLE[Length, Decimals] DECIMAL[Length, Decimals] DATE DATETIME TIMESTAMP TIME ENUM SET

4 bytes 8 bytes 4 bytes 8 bytes Length +1 bytes or Length + 2 bytes 3 bytes 8 bytes 4 bytes 3 bytes 1 or 2 bytes 1, 2, 3, 4, or 8 bytes

Range of -2,147,483,648 to 2,147,483,647 or 0 to 4,294,967,295 unsigned Range of -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 or 0 to 18,446,744,073,709,551,615 unsigned A small number with a floating decimal point. A large number with a floating decimal point. A DOUBLE stored as a string, allowing for a fixed decimal point. In the format YYYY-MM-DD In the format YYYY-MM-DD HH:MM:SS. In the format YYYYMMDDHHMMSS; acceptable range ends in the year 2037. In the format of HH:MM:SS. Short for enumeration, that is, each column can have one of several possible values. Like ENUM except that each column can have more than one of several possible values.

Microsoft Access Data Types


Below is a list of data types for Microsoft Access (adapted from Schwartz S. Microsoft Office Access 2003. A visual quickstart guide. Peachpit Press: Berkeley 2004). In Microsoft Access, each field can be one of the following data types: 1. Text: a Text field can store any combination of typed characters: letters, numbers, and punctuation. 2. Memo: a Memo field is an extra large Text field (up to 65,535 characters). When sorting on a Memo field, Access only considers the first 255 characters. 3. Number: a Number field is used to store most types of numeric data (with the exception of monetary amounts which can be stored using the Currency field type). 4. Currency: this data type has been designed specifically to store currency amounts and prevent rounding errors. 5. Auto Number: the Auto Number data type is used to automatically assign a new number to a primary key field, increasing the previously assigned number by one. Data stored in an Auto Number field cannot be edited. 2

6. Date/Time: a Date/Time field is used to store dates or times. A specific format to display dates and times can be selected. 7. Yes/No: a Yes/No field is the Access data type for recording one of two opposing values. Yes/No fields can be formatted as Yes/No, True/False, or On/Off (although all are equivalent). Every Yes/No field is formatted as a single check box; checked is Yes, True, or On whereas unchecked is No, False, or Off. 8. OLE Object: Object Linking and Embedding (OLE) Object data types enable you to embed or link to documents created in other programs, such as worksheets created in MS Excel, images (eg, gif, or jpg files), or word processing files (eg, doc files); one can either embed the object in the Access data file or link the object to the database, thereby storing a pointer or a reference to the original document. OLE is the technology which allows an object (such as a spreadsheet) to be embedded (and/or linked) inside of another document (like a word processor document). 9. Hyperlink: the Hyperlink data type enables you to store a clickable address in the field. For example: a. http:// b. mailto: c. ftp:// 10. Lookup Wizard: a Lookup Wizard field type enables a field to display a drop-down list of values from which the user can choose; this list of values can come from another table, a query, or event he same table.

A Review of Bits and Bytes


(This section has been adapted from Marshall Brains article on How Bits and Bytes Work from http://www.howstuffworks.com.) In order to understand a little about field types and their bytes, its important to review briefly what bytes (and bits) are. Lets first review the concept of decimal numbers. I think everyone is familiar with decimal places and digits of a decimal number. Each digit can range from 0 to 9, that is, ten possible values. For example, we know that the number 1,488 has four digits with four decimal places: 8 ones, 8 tens, 4 hundreds, and 1 thousands. So the number 1,488 could be expressed as: (1*1000) + (4*100) + (8*10) + (8*1) = 1000 + 400 + 80 + 8 = 1,488 Similarly, we could express the same number in terms of powers of 10: (1*10^3) + (4*10^2) + (8*10^1) + (8*10^0) = 1000 + 400 + 80 + 8 = 1,488 Recall, anything to the zero power is equal to 1. Bits and bytes could be viewed in a similar way. Computers use the base-2 system known as the binary number system just as the base-10 number system is known as the decimal number system.

Each binary digit (also called a bit for Binary digIT) can only take on one of two values, 1 or 0, instead of 0 to 9 like the decimal system. So the binary number 1100 would represent: (1*2^3) + (1*2^2) + (0*2^1) + (0*2^0) = 12 This time we use base of 2 instead of base of 10. A collection of 8 bits is known as one byte. With 8 bits in a byte, one can represent 256 values ranging from 0 to 255: 00000000 = (0*2^7) + (0*2^6) + (0*2^5) + (0*2^4) + (0*2^3) + (0*2^2) + (0*2^1) + (0*2^0) =0 11111111 = (1*2^7) + (1*2^6) + (1*2^5) + (1*2^4) + (1*2^3) + (1*2^2) + (1*2^1) + (1*2^0) = 255 Three bytes (24 bits) can then represent a number ranging from 0 to 16,777,215. 000000000000000000000000 = (0*2^23) + (0*2^22) + (0*2^21) + + (0*2^4) + (0*2^3) + (0*2^2) + (0*2^1) + (0*2^0) =0 111111111111111111111111 = (1*2^23) + (1*2^22) + (1*2^21) + + (1*2^4) + (1*2^3) + (1*2^2) + (1*2^1) + (1*2^0) = 16,777,215 Bytes are used to hold individual characters in a text document. For example, 00100000 is equal to 32 which is the numeric code for space. So text characters are coded as numbers which are stored as bytes in a computer file. The computer usually stores each character in 1 byte.

You might also like