更改mysql中一个单元格的数据

发布于 2024-09-05 11:48:15 字数 74 浏览 5 评论 0 原文

如何仅更改 mysql 表的一个单元格中的数据。 我对 UPDATE 有问题,因为它使列中的所有参数发生变化,但我只想更改一个。如何?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

月野兔 2024-09-12 11:48:15

您可能需要指定要更新哪些行...

UPDATE 
    mytable
SET 
    column1 = value1,
    column2 = value2
WHERE 
    key_value = some_value;

You probably need to specify which rows you want to update...

UPDATE 
    mytable
SET 
    column1 = value1,
    column2 = value2
WHERE 
    key_value = some_value;
讽刺将军 2024-09-12 11:48:15

我的答案是重复其他人之前说过的内容,但我想我应该添加一个使用 MySQL 的示例,只是因为之前的答案对我来说有点神秘。

更新单行列所需命令的一般形式:

UPDATE my_table SET my_column='new value' WHERE something='some value';

这是一个示例。

之前

mysql> select aet,port from ae;
+------------+-------+
| aet        | port  |
+------------+-------+
| DCM4CHEE01 | 11112 | 
| CDRECORD   | 10104 | 
+------------+-------+
2 rows in set (0.00 sec)

进行更改

mysql> update ae set port='10105' where aet='CDRECORD';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

之后

mysql> select aet,port from ae;
+------------+-------+
| aet        | port  |
+------------+-------+
| DCM4CHEE01 | 11112 | 
| CDRECORD   | 10105 | 
+------------+-------+
2 rows in set (0.00 sec)

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.

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)
蒗幽 2024-09-12 11:48:15

UPDATE 将仅更改您特别列出的列。

UPDATE some_table
SET field1='Value 1'
WHERE primary_key = 7;

WHERE 子句限制更新哪些行。通常,您可以使用它来标识表的主键(或 ID)值,以便您只更新一行。

SET 子句告诉 MySQL 要更新哪些列。您可以根据需要列出任意数量的列。您未列出的任何内容都不会得到更新。

UPDATE will change only the columns you specifically list.

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.

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 not get updated.

潇烟暮雨 2024-09-12 11:48:15

UPDATE 仅更改您指定的值:

UPDATE table SET cell='new_value' WHERE whatever='somevalue'

UPDATE only changes the values you specify:

UPDATE table SET cell='new_value' WHERE whatever='somevalue'
尬尬 2024-09-12 11:48:15

请尝试以下操作:

UPDATE TableName SET ValueName=@parameterName WHERE
IdName=@ParameterIdName

Try the following:

UPDATE TableName SET ValueName=@parameterName WHERE
IdName=@ParameterIdName
月隐月明月朦胧 2024-09-12 11:48:15

更新表 <表名> SET WHERE <代码><条件>

示例:

UPDATE TABLE teacher SET teacher_name='NSP' WHERE teacher_id='1'

UPDATE TABLE <tablename> SET <COLUMN=VALUE> WHERE <CONDITION>

Example:

UPDATE TABLE teacher SET teacher_name='NSP' WHERE teacher_id='1'
滿滿的愛 2024-09-12 11:48:15

试试这个。

UPDATE `database_name`.`table_name` SET `column_name`='value' WHERE `id`='1';

try this.

UPDATE `database_name`.`table_name` SET `column_name`='value' WHERE `id`='1';
反目相谮 2024-09-12 11:48:15

MySQL 中的某些列有一个“更新时”子句,请参阅:

mysql> SHOW COLUMNS FROM your_table_name;

我不确定如何更新它,但当我发现时会发布编辑。

Some of the columns in MySQL have an "on update" clause, see:

mysql> SHOW COLUMNS FROM your_table_name;

I'm not sure how to update this but will post an edit when I find out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文