当前位置:网站首页>MySQL learning summary 8: addition, deletion and modification of data processing

MySQL learning summary 8: addition, deletion and modification of data processing

2022-06-13 03:23:00 koping_ wu

1、 insert data

1.1 Insert the way 1:VALUES The way

situation 1: Insert data for the specified fields of the table

INSERT INTO  Table name (column1 [, column2, ..., columnn])
VALUES (value1 [,value2, ..., valuen]);

situation 2: Insert multiple records at the same time

INSERT INTO table_name(column1 [, column2, ..., columnn])
VALUES
(value1 [,value2, ..., valuen]),
(value1 [,value2, ..., valuen]),
......
(value1 [,value2, ..., valuen]);

   A that inserts multiple rows of records at the same time INSERT Statement is equivalent to multiple single line inserts INSERT sentence , But multi line INSERT Statement during processing More efficient . because MySQL Execute a single article INSERT Statement inserts more rows of data than using multiple INSERT Fast sentence , Therefore, when inserting multiple records, it is best to choose to use a single record INSERT Insert... In the form of a statement .

1.1 Insert the way 2: Insert the query results into the table

  INSERT Can also be SELECT Insert the result of the statement query into the table , At this time, it is not necessary to input the values of each record one by one , Just use one INSERT Statement and a line SELECT Statements can quickly insert multiple rows from one or more tables into a table .
   The basic syntax is as follows :

INSERT INTO  Target table name 
(tar_column1 [, tar_column2, ..., tar_columnn])
SELECT
(src_column1 [, src_column2, ..., src_columnn])
FROM  Source table name 
[WHERE condition]

2、 Update data

The syntax of the update statement is as follows :

UPDATE table_name
SET column1=value1, column2=value2, ... , column=valuen
[WHERE condition]

Take a chestnut : take id by 113 The employee's department is changed to 70.

UPDATE employees
SET   department_id = 70
WHERE employee_id = 113;

3、 Delete data

The syntax for deleting data is as follows :

DELETE FROM table_name [WHERE <condition>];

for instance : Delete departments The Department name in the table is ’Finance’ All the information about .

DELETE FROM departments
WHERE
department_name = 'Finance';
原网站

版权声明
本文为[koping_ wu]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280530399753.html