MySQL excellent learning database SQL syntax reference

Source: Internet
Author: User

I. data definition language)

A document language is a language defined for the format and form of a document. It is the first thing that every database needs to create, the table relationships, column primary keys in the table, and the reference relationships between tables are all planned at the beginning.

1. Create a table:

Create table table_name (
Column1 datatype [not null] [not null primary key],
Column2 datatype [not null],
...);

Note:

Datatype -- is the data format. For details, see the table.
Nut null-do not allow empty data (no data is provided ).
Primary key -- is the primary key of the table.

2. Change the table

Alter table table_name
Add column column_name datatype

Note: Add a column (the syntax of a column is not deleted.

Alter table table_name
Add primary key (column_name)

Note: You can change the table definition to set a column as a primary key.

Alter table table_name
Drop primary key (column_name)

Delete the definition of the primary key.

3. Create an index

Create index index_name on table_name (column_name)

Note: index the column of a table to increase the query speed.

4. Delete

Drop table_name
Drop index_name

  • 1
  • 2
  • Next Page
[Content navigation]
Page 1: Data Definition Page 2nd: Data Operations

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.