设计数据库


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 signedthe allowable range is from 128 to 127. If unsignedthe allowable range is from 0 to 255.
 
SMALLINT 
 A small integer that can be signed 
or unsigned. If signedthe allowable range is from 32768 to 32767. If unsignedthe allowable range is from 0 to 65535.
 
MEDIUMINT 
 A medium
-sized integer that can be signed or unsigned. If signedthe allowable range is from 8388608 to 8388607. If unsignedthe allowable range is from 0 to 16777215.
 
INT 
 A normal
-sized integer that can be signed or unsigned. If signedthe allowable range is from 2147483648 to 2147483647. If unsignedthe allowable range is from 0 to 4294967295.
 
BIGINT 
 A large integer that can be signed 
or unsigned. If signedthe allowable range is from 9223372036854775808 to 9223372036854775808. If unsignedthe 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,2where 2 is the number of decimalsDecimal precision can go to 24 places for a FLOAT.
 
DATE 
 A date in YYYY
-MM-DD formatbetween 1000-01-01 and 9999-12-31. For exampleDecember 30th1973 would be stored as 1973-12-30.
 
DATETIME 
 A date in YYYY
-MM-DD formatbetween 1000-01-01 and 9999-12-31plus hour and minute information in HH:MM:SS format. For example12:01 AM on December 30th1973 would be stored as 1973-12-30 00:01:00.
 
TIMESTAMP 
 A timestamp between midnight
January 11970 and sometime in 2037. You can define multiple lengths to the TIMESTAMP fieldwhich directly correlate to what is stored in itThe default length for TIMESTAMP is 14which stores YYYYMMDDHHMMSSThis looks like the DATETIME formatonly without the hyphens between numbers3:30 in the afternoon on December 30th1973 would be stored as 19731230153000. Other definitions of TIMESTAMP are 12 (YYMMDDHHMMSS), (YYYYMMDD), and (YYMMDD).
 
CHAR 
 A fixed
-length string between 1 and 255 characters in lengthright-padded with spaces to the specified length when storedDefining a length is not requiredbut the default is 1.
 
VARCHAR 
 A variable
-length string between 1 and 255 characters in lengthYou 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 datasuch as images or other types of filesFields defined as TEXT also hold large amounts of datathe difference between the two is that sorts and comparisons on stored data are case sensitive on BLOBs and case insensitive in TEXT fieldsYou do not specify a length with BLOB or TEXT.
 
ENUM
 An enumeration 
(list). When defining an ENUMyou 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 NULLcould ever populate that fieldENUMs can have 65535 different values