MySQL common commands (4) Inserting, querying, deleting, modifying data

Source: Internet
Author: User

The INSERT INTO command is used to insert data into the table.

INSERT INTO command format: INSERT into < table name > [(< Field name 1>[,.. < field name n >])] VALUES (value 1) [, (value N)];

First show tables; There is a MyClass table. insert two records into table MyClass, these two records indicate that: 1 is named Tom with a score of 96.45, 2 for the named Joan, and 82.99 for the named Wang with the number 3.

[SQL] Plain Text View Copy Code
INSERT into MyClass values (null, ' Tom ', 1,96.45), (null, ' Joan ', 1,82.99), (null, ' Wang ', 2, 96.59);



The Select from command is used to query the data in the table.
Command format: Select < Field 1, Field 2, ...> from < table name > where < expression >;

For example, view all the data in the table MyClass:

[SQL] Plain Text View Copy Code
Slect * from MyClass;


Query results
<ignore_js_op>

query all data. png (30.95 KB, download number: 0)

Download attachments

2016-6-25 14:32 Upload


The delete from command is used to delete data from a table.

Delete from command format: Delete from table name where expression

For example, delete the record numbered 1 in table MyClass:

[SQL] Plain Text View Copy Code
Delete from MyClass where id=1;

The data in the following table is removed as follows:

[SQL] Plain Text View Copy Code
Mysql> Select * FROM myclass;+----+------+-----+--------+| ID | name | sex | Degree |+----+------+-----+--------+|  2 | Joan |   1 |  82.99 | |  3 | Wang |   2 |  96.59 |+----+------+-----+--------+2 rows in Set (0.00 sec)


The update set command is used to modify the data in the table.

Update SET command format: Update table name SET field = new value,... where condition;

Examples are as follows:

[Shell] Plain Text View Copy Code
Update MyClass set name= ' ck ' where id=2;


The updated data is as follows:

[SQL] Plain Text View Copy Code
Mysql> SELECT * FROM myclass;+----+------+-----+--------+| ID | name | sex | Degree |+----+------+-----+--------+|  2 | CK   |   1 |  82.99 | |  3 | Wang |   2 |  96.59 |+----+------+-----+--------+2 rows in Set (0.00 sec)

http://www.sodu666.com/1/
http://tieba.sodu666.com/

MySQL common commands (4) Inserting, querying, deleting, modifying data

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.