MySQL 在mysql中更改一个单元格的数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3024546/
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
Change One Cell's Data in mysql
提问by kasrsf
How can I change the data in only one cell of a mysql table. I have problem with UPDATE because it makes all the parameters in a column change but I want only one changed. How?
如何仅更改 mysql 表的一个单元格中的数据。我对 UPDATE 有问题,因为它使列中的所有参数都更改,但我只想更改一个。如何?
回答by Brian Hooper
You probably need to specify which rows you want to update...
您可能需要指定要更新的行...
UPDATE
mytable
SET
column1 = value1,
column2 = value2
WHERE
key_value = some_value;
回答by slm
My answer is repeating what others have said before, but I thought I'd add an example, using MySQL
, only because the previous answers were a little bit cryptic to me.
我的回答是重复别人之前说过的话,但我想我会添加一个例子,使用MySQL
,只是因为以前的答案对我来说有点神秘。
The general form of the command you need to use to update a single row's column:
您需要用来更新单行列的命令的一般形式:
UPDATE my_table SET my_column='new value' WHERE something='some value';
And here's an example.
这是一个例子。
BEFORE
前
mysql> select aet,port from ae;
+------------+-------+
| aet | port |
+------------+-------+
| DCM4CHEE01 | 11112 |
| CDRECORD | 10104 |
+------------+-------+
2 rows in set (0.00 sec)
MAKING THE CHANGE
做出改变
mysql> update ae set port='10105' where aet='CDRECORD';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
AFTER
后
mysql> select aet,port from ae;
+------------+-------+
| aet | port |
+------------+-------+
| DCM4CHEE01 | 11112 |
| CDRECORD | 10105 |
+------------+-------+
2 rows in set (0.00 sec)
回答by VoteyDisciple
UPDATE
will change only the columns you specifically list.
UPDATE
将仅更改您专门列出的列。
UPDATE some_table
SET field1='Value 1'
WHERE primary_key = 7;
The WHERE
clause limits which rows are updated. Generally you'd use this to identify your table's primary key (or ID) value, so that you're updating only one row.
该WHERE
子句限制更新哪些行。通常,您会使用它来标识表的主键(或 ID)值,以便您只更新一行。
The SET
clause tells MySQL which columns to update. You can list as many or as few columns as you'd like. Any that you do not list will notget updated.
该SET
子句告诉 MySQL 要更新哪些列。您可以根据需要列出任意数量的列。任何你不列表将不会得到更新。
回答by gruntled
UPDATE
only changes the values you specify:
UPDATE
仅更改您指定的值:
UPDATE table SET cell='new_value' WHERE whatever='somevalue'
回答by user3668628
Try the following:
请尝试以下操作:
UPDATE TableName SET ValueName=@parameterName WHERE
IdName=@ParameterIdName
回答by NSP
UPDATE TABLE<tablename>
SET<COLUMN=VALUE>
WHERE<CONDITION>
更新表<tablename>
SET <COLUMN=VALUE>
WHERE<CONDITION>
Example:
例子:
UPDATE TABLE teacher SET teacher_name='NSP' WHERE teacher_id='1'
回答by abhay
try this.
尝试这个。
UPDATE `database_name`.`table_name` SET `column_name`='value' WHERE `id`='1';
回答by Jake_Howard
Some of the columns in MySQL have an "on update" clause, see:
MySQL 中的某些列具有“on update”子句,请参阅:
mysql> SHOW COLUMNS FROM your_table_name;
I'm not sure how to update this but will post an edit when I find out.
我不知道如何更新这个,但当我发现时会发布一个编辑。