当前位置:网站首页>SQL modification statement
SQL modification statement
2022-07-02 15:46:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
If we want to modify the data of tables in the database , At this time, we will use UPDATE sentence .
UPDATE The basic syntax of a sentence is :
UPDATE < Table name > SET Field 1= value 1, Field 2= value 2, … WHERE …;
for example , We want to update employees surface id=100 The record of last_name and salary These two fields , Write first UPDATE employees SET name=” eldest brother ”, salary = 54000, And then in WHERE Clause to write the filter conditions of the rows that need to be updated id=100:
namely UPDATE employees SET last_name=‘ eldest brother ’, salary=54000 WHERE employee_id=100;
– Before the change :
– After modification :
Here we find UPDATE Of the statement WHERE Conditions and SELECT Of the statement WHERE The conditions are actually the same , Therefore, multiple records can be updated at one time :
UPDATE employees SET last_name=‘TEST’, salary=54000 WHERE employee_id>=101 and employee_id<=105;
– Before the change :
– After modification :
stay UPDATE In the sentence , We can also use expressions when updating fields .
for example , Put all the 50000 For employees with a salary of more than yuan, add 666 element :
UPDATE employees SET salary=54000+666 WHERE salary >= 50000;
– Query results
among ,SET salary=54000+666 It's for the current line salary The value of the field is added 666.
If WHERE The condition does not match any record ,UPDATE Statements do not report errors , But no records will be updated .
UPDATE Statement can have no WHERE Conditions , for example :
UPDATE employees SET salary=54000+666
This is the time , All records of the entire table will be updated . therefore , In execution UPDATE Be very careful when making statements , It's better to use SELECT Statement to test WHERE Whether the condition filters out the desired recordset , And then use UPDATE updated .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/147718.html Link to the original text :https://javaforall.cn
边栏推荐
- locate: 无法执行 stat () `/var/lib/mlocate/mlocate.db‘: 没有那个文件或目录
- Experiment collection of University "Fundamentals of circuit analysis". Experiment 7 - Research on sinusoidal steady-state circuit
- 【LeetCode】189-轮转数组
- 【LeetCode】1905-统计子岛屿
- Comparison between rstan Bayesian regression model and standard linear regression model of R language MCMC
- 【LeetCode】200-岛屿数量
- Aiko ai Frontier promotion (7.2)
- 6092. Replace elements in the array
- (5) Flink's table API and SQL update mode and Kafka connector case
- Leetcode skimming -- sum of two integers 371 medium
猜你喜欢
密码学基础知识
[salesforce] how to confirm your salesforce version?
PTA ladder game exercise set l2-001 inter city emergency rescue
【LeetCode】1162-地图分析
[leetcode] 417 - Pacific Atlantic current problem
03. Preliminary use of golang
Comparison between rstan Bayesian regression model and standard linear regression model of R language MCMC
Experiment collection of University "Fundamentals of circuit analysis". Experiment 7 - Research on sinusoidal steady-state circuit
《大学“电路分析基础”课程实验合集.实验五》丨线性有源二端网络等效电路的研究
《大学“电路分析基础”课程实验合集.实验四》丨线性电路特性的研究
随机推荐
Name of institution approved in advance
Custom exception
【LeetCode】876-链表的中间结点
Astra: could not open "2bc5/ [email protected] /6“: Failed to set USB interface
The task cannot be submitted after the installation of flick is completed
将点云坐标转换成世界坐标的demo
Moveit 避障路径规划 demo
【LeetCode】1905-统计子岛屿
[leetcode] 417 - Pacific Atlantic current problem
《大学“电路分析基础”课程实验合集.实验七》丨正弦稳态电路的研究
[leetcode] 344 reverse string
(Video + graphic) machine learning introduction series - Chapter 5 machine learning practice
2303. Calculate the total tax payable
PyObject 转 char* (string)
How to intercept the value of a key from the JSON string returned by wechat?
自定义异常
[leetcode] 695 - maximum area of the island
夏季高考文化成绩一分一段表
PTA ladder game exercise set l2-001 inter city emergency rescue
[leetcode] 189 rotation array