To create a table:
Basic form
CREATE TABLE [if not EXISTS] table name ( field list, [ constraint or index list ]) [ table Options list ];
Note: Lists are all " multiple ", separated from each other by commas.
Field Basic form: field Name type [ field modifier property ];
Field property settings
Not NULL: Is not empty, indicating that the field cannot have a value of "null" . Do not write, the default is to be empty
Auto_increment: sets the value of the Int type field to " self -grow", meaning that its value does not need to be " written" and is automatically obtained and incremented
This property must be used with primary KEY or unique key .
[Primary] Key: Sets the primary key. Is the unique key " enhanced ": it cannot be duplicated and cannot use null, and can be used as a "key value" for determining any row of data , most commonly similar to the following:where Id= 8; or where user_name = ' Zhangsan ';
Typically, each table should have a primary key, and most tables prefer to use an ID and self-growing type as the primary key.
However: only one primary key can be set for a table.
Unique [key]: set to Unique key: The value of all rows representing the field cannot be duplicated (uniqueness).
Default ' defaults ': Sets a value that the field automatically uses when no data is inserted.
Comment ' field comment ':
Example:
》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》
Index settings
What is an index:
An index is a " built-in table" of data that is stored in the form of a " sort" of data for one of the fields of a real table .
The effect is: greatly improve the speed of table lookup data! -- its efficiency (speed) can match the binary search.
Note: The index reduces the speed of additions and deletions while providing the search speed.
Indexing is a very simple thing to create (design) tables, in the following form:
Index type ( field name 1, field name 2, ...). ) // can be indexed using multiple fields, but is usually a
There are several indexes:
Normal index:key ( field name 1, field name 2, ....) ): It only has the basic function of indexing- - speed up
Unique index: Uniquekey ( field name 1, field name 2, ....) )
Primary KEY index:primary key ( field name 1, field name 2, ....) )
Full-text index:fulltext ( field name 1, field name 2, ....) )
Example:
MySQL Basics (3)--Create