Mysql will have basic syntax at a glance, and mysql basic syntax

Source: Internet
Author: User

Mysql will have basic syntax at a glance, and mysql basic syntax

Create a table

Create table <table Name> (
<Field Name> type (length) not null primary key auto_increment, ** primary key
Name char (20) not null,
Sex int (4) not nullDefault'0', ** default key
Degree double (16, 2)

)

 

Delete table

Drop table <table Name>;

Clear table

Delete from <Table Name>;

 

Insert data

Insert into <Table Name> [(<field name 1> [,... <field name n>])] values (value 1) [, (value n)]

 

Query a table

Select <Field 1, Field 2,...> from <Table Name> where <expression>

Query the first few fields of a table

Select * from MyClass order by id limit 0, 2;

Total query Fields

Select sum ('field name') from Table Name

Query fields in ascending and descending order

In descending order: select * from table name where expression order by field name desc

Ascending order: select * from table name where Putout = true order by time asc

 

Delete table

Delete from table name where expression

 

Modify Table

Update table name set field = new value ,... Where condition

 

Add Table Fields

Alter table name add other field types;

<1 primary key: alter table name add primary key (field name );

<2 unique constraint: alter table name add unique index name (field name );

 

Delete table fields

Alter table Name drop field name

 

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.