当前位置:网站首页>MySQL data addition, deletion and modification
MySQL data addition, deletion and modification
2022-07-22 05:14:00 【Program three two lines】
1、 insert data
1.1、 Inserts data in the default order for all fields of the table
INSERT INTO Table name VALUES (value1,value2,....); In the value list, you need to specify a value for each field of the table , And the order of values must be the same as that of fields in the data table INSERT INTO departments VALUES (70, 'Pub', 100, 1700);
1.2、 Insert data for the specified fields of the table
INSERT INTO Table name (column1 [, column2, …, columnn]) VALUES (value1 [,value2, …, valuen]); Insert data for the specified fields of the table , Is in the INSERT Statement inserts values into only some fields , The values of other fields are the values of the table definition The default value is . stay INSERT Column names are arbitrarily listed in the clause , But once listed ,VALUES To insert value1,....valuen Need and column1,...columnn The columns correspond one by one . If the type is different , Will not be able to insert , also MySQL There will be mistakes
1.3、 Insert multiple records at the same time
INSERT Statement can insert multiple records into the data table at the same time , Specify multiple value lists when inserting , Each value list is separated by commas open , The basic syntax is as follows : INSERT INTO table_name(column1 [, column2, …, columnn]) VALUES (value1 [,value2, …, valuen]), (value1 [,value2, …, valuen]), …… (value1 [,value2, …, valuen]); Use INSERT When inserting multiple records at the same time ,MySQL It will return some additional information that is not available when performing single line insertion , The content of this information The meaning is as follows : ● Records: Indicates the number of records inserted . ● Duplicates: Indicates the records that were ignored during insertion , The reason may be that Some records contain duplicate primary key values . ● Warnings: Data values indicating a problem , For example, data type conversion occurs .
1.4、 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 To use a INSERT Statement and a line SELECT Statements can be quickly inserted from one or more tables into a table Multiple lines .
INSERT INTO emp2 SELECT * FROM employees WHERE department_id = 90; INSERT INTO sales_reps(id, name, salary, commission_pct) SELECT employee_id, last_name, salary, commission_pct FROM employees WHERE job_id LIKE '%REP%';
2、 Delete data
DELETE FROM table_name [WHERE ];
table_name Specify the table to delete ;“[WHERE ]” Is an optional parameter , Specify deletion criteria , without WHERE Clause , DELETE Statement will delete all records in the table .
3、 Modifying data
UPDATE table_name SET column1=value1, column2=value2, … , column=valuen [WHERE condition] You can update more than one piece of data at a time . If you need to roll back data , It needs to be guaranteed in DML front , Set it up :SET AUTOCOMMIT = FALSE; Use WHERE Clause specifies the data to be updated UPDATE employees SET department_id = 70 WHERE employee_id = 113; If omitted WHERE Clause , Then all data in the table will be updated .
4、 MySQL8 New characteristics : Calculated column
What is a calculated column ? Simply put, the value of a column is calculated from other columns . for example ,a The column value is 1、b The column value is 2,c Column Manual insertion is not required , Definition a+b As the result of the c Value , that c Is the calculation column , It is calculated from other columns . stay MySQL 8.0 in ,CREATE TABLE and ALTER TABLE Both support adding calculation Columns . Let's say CREATE TABLE Take as an example Explain . give an example : Define data table tb1, Then define the fields id、 Field a、 Field b And field c, Which field c Is a calculated column , Used to calculate a+b Of value . First create a test table tb1, The statement is as follows :
CREATE TABLE tb1( id INT, a INT, b INT, c INT GENERATED ALWAYS AS (a + b) VIRTUAL );
边栏推荐
- Merging and sorting ideas and examples
- [chestnut sugar GIS] WPS -- how to fill the space in the content of the previous line
- 基于MIPI的高性能成像系统
- pip下载包时出现不适配导致无法下载安装包:error: subprocess-exited-with-error;error: metadata-generation-failed;
- [chestnut sugar GIS] bat - how to rename the data in sub files in batch
- 图像文本跨模态细粒度语义对齐-置信度校正机制 AAAI2022
- PL/SQL 异常
- CITIC branch Mobile has registered: it plans to raise 4billion yuan to create a listed enterprise for research and development of 5g in optical valley
- JVM first acquaintance
- Babbitt metauniverse daily must read: ask senior government officials to disclose all their investments in NFT? What else did the legal consultation released by the U.S. government ethics office say
猜你喜欢
深度之眼(十五)——导数
pip下载包时出现不适配导致无法下载安装包:error: subprocess-exited-with-error;error: metadata-generation-failed;
The installation package cannot be downloaded due to the mismatch when PIP downloads the package: error: subprocess exited with error; error: metadata-generation-failed;
[BSP video tutorial] BSP video tutorial No. 20: play with serial port special topics, Hal library, ll library and register implementation methods, as well as learning several key sequence diagrams in
【板栗糖GIS】如何批量删除多个文件夹里的同名空文件
Lianying medical passed the registration: it plans to raise 12.5 billion yuan, and Xue min controls 32% of the equity
MySQL storage engine
Scratch score query Electronic Society graphical programming scratch grade examination level 4 true questions and answers analysis June 2022
Go system monitoring
Here comes the multilingual model that everyone can use! Support 59 languages, parameters 176billion, 1000 scientists jointly launched
随机推荐
Zhenhua scenery semiconductor passed the registration: with an annual revenue of 500million, China Electronics is the actual controller
Anfulai embedded weekly report no. 274: 2022.07.11--2022.07.17
Yunzhou intelligent IPO was terminated: the annual revenue was 250million, the loss was 130million, and it was planned to raise 1.55 billion
Open source GIS system
DRF--JWT2-用户认证-自定义控制simpjwt返回内容
Apple lost 340million Yuan due to bad keyboard. SpaceX received the order. Webb's successor, meta, sued meta. Today, more new things are here
How to exit the current C application
Introduction to gtsam
【板栗糖GIS】arcmap—如何快速生成四至信息
【苏州大学】考研初试复试资料分享
【板栗糖GIS】arcmap——如何制作面数据的文字四至
mysql数据增删改
Go system monitoring
【板栗糖GIS】bat—如何对子文件中的数据进行批量重命名
[Suzhou University] information sharing of postgraduate entrance examination and re examination
[chestnut sugar GIS] bat - how to delete data with the same suffix under subfolders
The installation package cannot be downloaded due to the mismatch when PIP downloads the package: error: subprocess exited with error; error: metadata-generation-failed;
Navicat 导入sql脚本文件
Mipi based high performance imaging system
scratch成绩查询 电子学会图形化编程scratch等级考试四级真题和答案解析2022年6月