MySQL Basics (3)--Create

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.