设计数据库
Creating a table is easy—it's the planning that takes some brainpower. To create a simple table, you only need to give it a name. But that would make for a boring table, because it wouldn't contain any columns (fields) and couldn't hold any data. So besides the name, you should know the number of fields and the types of fields you want to have in your table.
PHP 代码:
TINYINT
A very small integer that can be signed or unsigned. If signed, the allowable range is from 128 to 127. If unsigned, the allowable range is from 0 to 255.
SMALLINT
A small integer that can be signed or unsigned. If signed, the allowable range is from 32768 to 32767. If unsigned, the allowable range is from 0 to 65535.
MEDIUMINT
A medium-sized integer that can be signed or unsigned. If signed, the allowable range is from 8388608 to 8388607. If unsigned, the allowable range is from 0 to 16777215.
INT
A normal-sized integer that can be signed or unsigned. If signed, the allowable range is from 2147483648 to 2147483647. If unsigned, the allowable range is from 0 to 4294967295.
BIGINT
A large integer that can be signed or unsigned. If signed, the allowable range is from 9223372036854775808 to 9223372036854775808. If unsigned, the allowable range is from 0 to 18446744073709551615.
FLOAT
A floating point number that cannot be unsigned. You can define the display length (M) and the number of decimals (D). This is not required and will default to 10,2, where 2 is the number of decimals. Decimal precision can go to 24 places for a FLOAT.
DATE
A date in YYYY-MM-DD format, between 1000-01-01 and 9999-12-31. For example, December 30th, 1973 would be stored as 1973-12-30.
DATETIME
A date in YYYY-MM-DD format, between 1000-01-01 and 9999-12-31, plus hour and minute information in HH:MM:SS format. For example, 12:01 AM on December 30th, 1973 would be stored as 1973-12-30 00:01:00.
TIMESTAMP
A timestamp between midnight, January 1, 1970 and sometime in 2037. You can define multiple lengths to the TIMESTAMP field, which directly correlate to what is stored in it. The default length for TIMESTAMP is 14, which stores YYYYMMDDHHMMSS. This looks like the DATETIME format, only without the hyphens between numbers; 3:30 in the afternoon on December 30th, 1973 would be stored as 19731230153000. Other definitions of TIMESTAMP are 12 (YYMMDDHHMMSS), 8 (YYYYMMDD), and 6 (YYMMDD).
CHAR
A fixed-length string between 1 and 255 characters in length, right-padded with spaces to the specified length when stored. Defining a length is not required, but the default is 1.
VARCHAR
A variable-length string between 1 and 255 characters in length. You must define a length when creating a VARCHAR field.
BLOB or TEXT
A field with a maximum length of 65535 characters. BLOBs are "Binary Large Objects" and are used to store large amounts of binary data, such as images or other types of files. Fields defined as TEXT also hold large amounts of data; the difference between the two is that sorts and comparisons on stored data are case sensitive on BLOBs and case insensitive in TEXT fields. You do not specify a length with BLOB or TEXT.
ENUM
An enumeration (list). When defining an ENUM, you are creating a list of items from which the value must be selected (or it can be NULL). For example, if you wanted your field to contain either "A" or "B" or "C", you would define your ENUM as ENUM ('A', 'B', 'C') and only those values (or NULL) could ever populate that field. ENUMs can have 65535 different values.