learn database design with mysql - chapter 4 - data types

Post on 16-Aug-2015

11 Views

Category:

Education

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

DATABASE DESIGN USING MYSQL

Understanding Data Types

3 CATEGORIES

MySQL offers many data types but places those data types into 3 categories

1. Numeric Data Types

2. String Data Types

3. Date and Time Data Types

SIGNED VS. UNSIGNED

• An Unsigned data type can not be negative but

has twice as large a range than positive integers

• A Signed data type can have negative values

• The types TINYINT, SMALLINT, MEDIUMINT,

INT and BIGINT all have signed and unsigned

versions.Type Storage Min Max INT 4 -2147483648 2147483647 INT UNSIGNED 4 0 4294967295

NUMERIC DATA TYPES

• INT – Normal sized integer. Width up to 11 digits• TINYINT – Very small integer. 0 – 255 and a width

up to 4 digits. Synonym for BOOLEAN• SMALLINT – Width of 5 digits• MEDIUMINT – Width of 9 digits• BIGINT – Up to 20 digits

FLOAT – Floating point number. Can define length and number of decimalsDOUBLE – Double precision floating point numberDECIMAL – Unpacked floating point number

STRING DATA TYPES

• CHAR – A fixed length string 1-255 chars in length. Not required to specify a length, defaults to 1

• VARCHAR – Variable-length between 1-255 chars. Must have a defined length

• BLOB or TEXT – Max length of 65535 characters. BLOBs can store large binary data like images, but I would suggest NOT storing images in a database

• TINYBLOB OR TINYTEXT – Max length of 255• MEDIUMBLOB or MEDIUMTEXT – Max length of

16777215• LONGBLOB or LONGTEXT – Max length up to

4294967295 • ENUM – An enumeration which is basically a list. Use to

create a list of items for which a value must be selected.

DATE AND TIME TYPES

• DATE – A date value in YYYY-MM-DD format. September 10th, 1981 would be stored as 1981-09-10

• DATETIME - A date and time combination in YYYY-MM-DD HH:MM:SS format,

• TIMESTAMP - A timestamp between midnight, January 1, 1970 and sometime in 2037. This looks like the previous DATETIME format, only without the hyphens .

• TIME -Stores the time in HH:MM:SS format• YEAR -Stores a year in 2-digit or 4-digit format.

THAT’S IT!

top related