SQL-DML (operation on data in the table)

DML modify the data in the table

Including three parts

adding data

INSERT [INTO] 表名 [字段名] VALUES (字段值)

INSERT INTO table name: adding data representing where to tables in the
(field name 1, field name 2, ...): to give what field settings
VALUES (value 1, value 2, ...): set a specific value

for the student information section added
Add a student information
Query student information
if To add all the attributes, you can omit a part
Add all information about a student
Query student information

delete data

1. Conditionally delete

DELETE FROM 表名 WHERE 字段名=;

Delete the record with id=1
Before deleting
After deleting

2. Delete without condition (the table still exists)

DELETE FROM 表名;

Before deleting
After deleting

3. Delete without conditions (the table does not exist, and a new table with the same will be created)

TRUNCATE TABLE 表名;

Add two more pieces of data
Before deleting

After deleting
After deleting

change the data

1. Conditional modification

UPDATE 表名 SET 列名=[WHERE 条件表达式]

Before modification
Change jack's age to 20
After modification

2. Modification without conditions

UPDATE 表名 SET 字段名=; -- 修改所有的行

Before modification
Change the age of all students to 20
After modification

Guess you like

Origin blog.csdn.net/weixin_45966880/article/details/114117456