Brother even learn Python class notes----MySQL data manipulation

Source: Internet
Author: User

Add data

Format: INSERT into table name [(field list)] VALUES (List of values ...); --Standard Add (Specify all fields, given all values)

Insert into Stu (ID,NAME,AGE,SEX,CLASSID) VALUES (1, ' Zhangsan ', +, ' m ', ' lamp138 ');
Query OK, 1 row affected (0.13 sec)


--Specify partial fields to add values
Insert into Stu (NAME,CLASSID) value (' Lisi ', ' lamp138 ');
Query OK, 1 row affected (0.11 sec)

--Do not specify a field to add values
Insert into Stu value (null, ' Wangwu ', +, ' w ', ' lamp138 ');
Query OK, 1 row affected (0.22 sec)

--Batch add value
INSERT INTO Stu values
(NULL, ' Zhaoliu ', ', ' w ', ' lamp94 '),
(NULL, ' uu01 ', ', ', ' m ', ' lamp94 '),
(NULL, ' uu02 ', ', ' w ', ' lamp92 '),
(NULL, ' qq02 ', ', ' m ', ' lamp92 '),
(NULL, ' uu03 ', +, ' m ', ' lamp138 '),
(NULL, ' qq03 ', Max, ' W ', ' lamp94 '),
(null, ' AA ', +, ' m ', ' lamp138 ');
Query OK, 7 rows affected (0.27 sec)
Records:7 duplicates:0 warnings:0
modifying data

Format: Update table name set field 1= value 1, field 2= value 2, field n= value n ... where condition

--change age of ID 11 to 35,sex to M value
Update Stu set age=35,sex= ' m ' where id=11;
Query OK, 1 row affected (0.16 sec)
Rows matched:1 changed:1 warnings:0

--Change the data value for ID values 12 and 14 to M,classid to lamp92
Update Stu set sex= ' m ', classid= ' lamp92 ' where ID in (12,14);
Query OK, 2 rows affected (0.09 sec)
Rows matched:2 Changed:2 warnings:0
Delete data

Format: Delete from table name [where condition]

--delete data in the Stu table with an ID value of 100
Delete from Stu where id=100;
Query OK, 0 rows Affected (0.00 sec)

--delete data from the Stu table with an ID value of 20 to 30
Delete from Stu where id>=20 and id<=30;
Query OK, 0 rows Affected (0.00 sec)

--delete data from the STU table with ID values from 20 to 30 (rank above)
Delete from Stu where ID between and 30;
Query OK, 0 rows Affected (0.00 sec)

--delete data with an ID value greater than 200 in the Stu table
Delete from Stu where id>200;
Query OK, 0 rows Affected (0.00 sec)

Brother even learn Python class notes----MySQL data manipulation

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.