Before adding a data table, make sure that already exists in the database, such as database yet please refer to the previous article new database
1. Create a table create table test (
id int PRIMARY KEY,
name varchar(11) NOT NULL,
aga int(11) NOT NULL,
creat_time datatime NOT NULL,
);
Format: Field Name Field Type + constraints +
2, common field type
Storage string:
varchar stored character variable length, the maximum length is 255, more than 255 characters, the format is automatically converted to text
Save a lot of text string with a maximum length of 65 535 characters
Storage time:
data format: YYYY-MM-DD, accurate to days, range 1000-01-01 to 9999-12-31
datatime format: YYYY-MM-DD: HH: MM: SS, accurate to the second, the range 1000-01-01 00:00:00 to 9999-12-31 23:59:59
Data storage number:
int -2147483648 2147483648 to digital
With decimal float floating decimal point
3, constraint
- NULL the NOT - can not store a column indicating a NULL value.
- UNIQUE - to ensure that each row of a column must have a unique value.
- KEY PRIMARY - combination of NOT NULL and UNIQUE. To ensure that a column (two columns or more rows in conjunction with) a unique identifier, facilitate easier and faster to a specific record in the table found.
- KEY a FOREIGN - a data table to ensure referential integrity values match another table.
- CHECK - guaranteed value in the column that meet the specified conditions.
- The DEFAULT - there is no provision to the default value of a column assignment
4, execute sql
5, view the database table