In Chapter 4, "Creating and Populating Database Tables" of PHP Essentials, I showed you a series of scripts used to create a database table. What I didn't do very well was explain the data types that are commonly used in MySQL (and other databases), as the limitations on field lengths and what not. For example, if you try to create a field of type TEXT and you give it a length, you'll probably get an error in your SQL statement.
The following chart is a handy reference to common data types. It's a short version of what can be found in the MySQL manual at http://www.mysql.com/Manual_chapter/manual_Reference.html#Column_types. For other database types, many of these definitions will hold true. However, always check your own database documentation to be sure!
DATA TYPE
DESCRIPTION
DEFINE LENGTH?
TINYINT
A very small integer.
SIGNED range is -128 to 127.
UNSIGNED range is 0 to 255.
Not required; defaults to 4.
SMALLINT
A small integer.
SIGNED range is -32768 to 32767.
UNSIGNED range is 0 to 65535.
Not required; defaults to 5.
MEDIUMINT
A medium-sized integer.
SIGNED range is -8388608 to 8388607.
UNSIGNED range is 0 to 16777215.
Not required; defaults to 9.
INT or
INTEGER
A normal-sized integer.
SIGNED range is -2147483648 to 2147483647.
UNSIGNED range is 0 to 4294967295.
Not required; defaults to 11.
BIGINT
A large integer.
SIGNED range is -9223372036854775808 to 9223372036854775807.
UNSIGNED range is 0 to 18446744073709551615.
Not required; defaults to 21.
FLOAT
A floating-point number that cannot be unsigned.
Not required; defaults to 10,2 where "2" is the number of decimals. Decimal precision can go to 24 for a FLOAT.
REAL or DOUBLE
A double-precision floating-point number that cannot be unsigned.
Not required; defaults to 16,4 where "4" is the number of decimals. Decimal precision can go to 53 for a DOUBLE.
NUMERIC or
DECIMAL
An unpacked floating-point number that cannot be unsigned.
Yes; both the display width (amount of numbers before the decimal point) and the decimal precision must be indicated (i.e. "17,15").
DATE
A date, in YYYY-MM-DD format, between 1000-01-01 and 9999-12-31.
No.
DATETIME
A date and time combination, in YYYY-MM-DD HH:MM:SS format, between 1000-01-01 00:00:00 and 9999-12-31 23:59:59.
No.
TIMESTAMP
A timestamp, between 1970-01-01 00:00:00 and sometime in 2037. TIMESTAMP depends on the assigned length of the field.
If length is 14, TIMESTAMP is YYYYMMDDHHMMSS.
If length is 12, TIMESTAMP is YYMMDDHHMMSS.
If length is 8, TIMESTAMP is YYYYMMDD.
If length is 6, TIMESTAMP is YYMMDD.
Not required; defaults to 14. Can be 6, 8, 12 or 14.
TIME
Time, in HH:MM:SS format.
No.
YEAR
A year, in 2 digit or 4 digit format.
If length is 2, YEAR can be 1970 to 2069 (70 to 69).
If length is 4, YEAR can be 1901 to 2155.
Not required; defaults to 4.
CHAR
A fixed-length string between 1 and 255 characters in length, right-padded with spaces to the specified length when stored.
Not required; defaults to 1.
VARCHAR
A variable-length string between 1 and 255 characters in length.
Yes.
TINYBLOB or
TINYTEXT
A BLOB or TEXT column with a maximum length of 255 characters.
No.
MEDIUMBLOB or
MEDIUMTEXT
A BLOB or TEXT column with a maximum length of 16777215 characters.
No.
LONGBLOB or
LONGTEXT
A BLOB or TEXT column with a maximum length of 4294967295 characters.
No.
BLOB or
TEXT
A BLOB or TEXT column with a maximum length of 65535 characters.
Anonymous wrote :240 hi,
i am looking for c++ api on linux for mysql.can anyone
help me .
Also is there an restriction on max number of columns
an mysql can have.plz help in this regard