"MySQL" Add, modify, delete, query grammar handouts

Source: Internet
Author: User


I. DML-Data Manipulation language

INSERT-New to implement data table data

UPDATE-Make changes to data table data

Delete-implements deletion of data table data

Second, INSERT

Syntax: INSERT into table name [(Field 1, Field 2,...)] VALUES (' Value 1 ', ' Value 2 ',...);

1.insert executes 1 times, you can add 1 records to the table

2. For auto-generated fields (auto_increment), you do not need to display the insert.


Third, UPDATE

Syntax: UPDATE table name SET column_name = value [, column_name2 = value2, ....]
[WHERE condition];

Example: Update student set sex= ' female '; --The sex column values of all data rows have been modified for female

UPDATE student SET sex= ' female ';

UPDATE student SET sex= ' man ' WHERE studentno=3;

UPDATE student SET sex= ' male ', gradeid=2, phone= ' 13985746510 ' WHERE studentno=1;

UPDATE student SET sex= ' unknown ' WHERE studentno between 2 and 3

Iv. DELETE

Syntax: DELETE from table name [WHERE condition];

Example: delete from student; --Delete all the data in the table

Delete from student where studentno=5; --Delete the record number 5

Delete from student where Studentno between 2 and 5; --Delete a record with a number between 2-5

Note: Deleted data can be retrieved through the log file.

Wu, TRUNCATE

Syntax: TRUNCATE [TABLE] table_name

Note: The deleted data cannot be recovered.

Vi. SELECT

Implement data query (data retrieval)

Syntax: SELECT [All | DISTINCT]
{* | table.* | [Table.field1 [As ALIAS1] [, table.field2 [as alias2]][, ...] }
From table_name [as Table_ alias]
[Left|out|inner join Table_name2] #联合查询
[WHERE ...] #指定结果需满足的条件
[GROUP by ...] #指定结果按照哪几个字段来分组
[Having ...] #过滤分组的记录必须满足的次要条件
[ORDER by ...] #指定查询记录按一个或者多个条件排序
[LIMIT {[offset,] row_count | row_count offset offset}]; #指定查询的记录从哪条至哪条

Example: SELECT * from grade; --Extracts all columns of data from the grade table (all rows)

Select distinct gradename from grade; --distinct used to reject repeated rows of data in the result

"MySQL" Add, modify, delete, query grammar handouts

Related Article

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.