MySQL Database DML Review

Table of contents

What is DML

adding data

change the data

delete data


What is DML

The full English name of DML is Data Manipulation Language (data manipulation language), which is used to add, delete, and modify data records in tables in the database.

adding data

关键字:INSERT(insert)

Add data to the specified field: insert into table name (field 1, field 2) values ​​(value 1, value 2);

Add data to all fields: insert into table name values ​​(value 1, value 2, ...);

Add data in batches (specified fields): insert into table name (field 1, field 2) values ​​(value 1, value 2), (value 1, value 2);

Add data in batches (all fields): insert into table name values ​​(value 1, value 2, ...), (value 1, value 2, ...);

Precautions:

1. When inserting data, the specified field order needs to correspond to the order of values.

2. String and date data should be enclosed in single quotes.

3. The size of the inserted data should be within the specified range of the field.

change the data

关键字:UPDATE(update)

Modify data: update table name set field 1 = value 1, field 2 = value 2, ...;

Conditional modification of data: update table name set field 1 = value 1, field 2 = value 2, ... where condition;

Precautions:

The conditions for modifying the statement may or may not exist. If there are no conditions, all data in the entire table will be modified.

delete data

关键字:DELETE(delete)

Delete data: delete from table name;

Conditional deletion of data: delete from table name where condition;

Precautions:

1. The DELETE statement may or may not have conditions. If there are no conditions, all data in the entire table will be deleted.

2. The DELETE statement cannot delete the value of a certain field. If you want to do so, you can use UPDATE to set the value of the field to NULL.

Guess you like

Origin blog.csdn.net/qq_74312711/article/details/134906340