SQL 更新所有行的列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9364572/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 14:29:08  来源:igfitidea点击:

Update a column for all the rows

sql

提问by rakesh bh

Table name: Employee
Column Name: Emp_name

表名:Employee
列名:Emp_name

Emp_namehas this contents:

Emp_name有这个内容:

xx\rama,
xx\rajesh,
xx\vignesh

I have to update the table Employee by removing xx\from all the rows of column Emp_name.

我必须通过xx\从 column 的所有行中删除来更新表 Employee Emp_name

Please help me.

请帮我。

回答by JNK

UPDATE Employee
SET EMP_Name = REPLACE(Emp_name, 'xx\', '')

This will remove all occurences of xx\in all records.

这将删除xx\所有记录中的所有出现。

回答by Bohemian

update Employee set
Emp_name = substring(Emp_name, 4)
where Emp_name like 'xx\%'; -- escaped backslash as per your database flavour 

回答by Curt

UPDATE [Employee]
SET Emp_Name=REPLACE(Emp_Name, 'xx\', '')


If you just want to just update the first, then do:

如果您只想更新第一个,请执行以下操作:

UPDATE [Employee]
SET Emp_Name=REPLACE(Emp_Name, 'xx\', '')
WHERE Emp_Id=(SELECT MIN(Emp_Id) FROM [Employee])

回答by nikolifish

I"m assuming this is in MS SQL, so if it is, this should work

我假设这是在 MS SQL 中,所以如果是,这应该有效

update Employee

更新员工

set emp_name = right(emp_name, len(emp_name) - 3)

设置 emp_name = right(emp_name, len(emp_name) - 3)