问题标签 [sql-update]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
18 回答
451419 浏览

mysql - MySQL 中的多个更新

我知道您可以一次插入多行,有没有办法在 MySQL 中一次更新多行(如在一个查询中)?

编辑:例如我有以下

我想将以下所有更新合并到一个查询中

0 投票
5 回答
20434 浏览

sql-server - SQL Server 2005 自动更新日期时间列 - LastUpdated

我定义了一个表(请参见下面的代码片段)。如何添加约束或其他任何内容,以便在更改行时自动更新 LastUpdate 列?

0 投票
5 回答
2927 浏览

mysql - 我可以在一个查询中更新/从表中选择吗?

我需要在查看页面时选择数据并更新“视图”列有没有办法在一个查询中执行此操作,还是我必须使用不同的查询?

0 投票
5 回答
1042593 浏览

sql - 我如何(或我可以)在多列上选择 DISTINCT?

我需要从一个表中检索所有行,其中 2 列组合起来都不同。所以我想要所有在同一天以相同价格发生的没有任何其他销售的销售。基于日期和价格的唯一销售将更新为活动状态。

所以我在想:

但是我的大脑比这更痛苦。

0 投票
6 回答
21523 浏览

sql - Update VERY LARGE PostgreSQL database table efficiently

I have a very large database table in PostgresQL and a column like "copied". Every new row starts uncopied and will later be replicated to another thing by a background programm. There is an partial index on that table "btree(ID) WHERE replicated=0". The background programm does a select for at most 2000 entries (LIMIT 2000), works on them and then commits the changes in one transaction using 2000 prepared sql-commands.

Now the problem ist that I want to give the user an option to reset this replicated-value, make it all zero again.

An update table set replicated=0;

is not possible:

  • It takes very much time
  • It duplicates the size of the tabel because of MVCC
  • It is done in one transaction: It either fails or goes through.

I actually don't need transaction-features for this case: If the system goes down, it shall process only parts of it.

Several other problems: Doing an

is also bad: It does a sequential scan all over the whole table which is too slow. If it weren't doing that, it would still be slow because it would be too many seeks.

What I really need is a way of going through all rows, changing them and not being bound to a giant transaction.

Strangely, an

is also slow, although it should be a good thing: Go through the table in DISK-order...

(Note that in that case there was also an index that covered this)

(An update LIMIT like Mysql is unavailable for PostgresQL)

BTW: The real problem is more complicated and we're talking about an embedded system here that is already deployed, so remote schema changes are difficult, but possible It's PostgresQL 7.4 unfortunately.

The amount of rows I'm talking about is e.g. 90000000. The size of the databse can be several dozend gigabytes.

The database itself only contains 5 tables, one is a very large one. But that is not bad design, because these embedded boxes only operate with one kind of entity, it's not an ERP-system or something like that!

Any ideas?

0 投票
8 回答
363 浏览

mysql - 盲目更新还是在哪里更新?

我有一个表格,其中包含有关游戏中城市的信息,您可以每回合建造一座建筑物,并以“usedBuilding”值记录。

每一回合我都会运行一个脚本,将 usedBuilding 更改为 0,问题是,以下两种方式中哪一种更快,使用哪种方式实际上是否重要?

0 投票
5 回答
15103 浏览

sql - 从另一个表的行批量更新一个表

2张桌子:

我想Employees.LeadCount通过计算Leads表中具有相同EmployeeID.

注意:可能有超过 1 个具有相同员工 ID 的潜在客户,所以我必须做一个DISTINCT(SUM(employeeID)).

0 投票
4 回答
109872 浏览

mysql - 当运行 UPDATE ... datetime = NOW(); 所有更新的行都会有相同的日期/时间吗?

当您运行类似于以下内容时:

在具有 1 000 000 000 条记录的表上,查询需要 10 秒才能运行,所有行的时间是否完全相同(分钟和秒)还是不同的时间?换句话说,是查询开始的时间还是每行更新的时间?

我正在运行 MySQL,但我认为这适用于所有数据库。

0 投票
2 回答
9574 浏览

mysql - 从另一个表更新列 - mySQL 3.5.2

我尝试了几种方法来从另一个表更新 mySQL 数据库表中的列,但没有任何运气。

我在某处读到版本 3.5.2 不支持多表更新,我需要基于代码的解决方案 - 对吗?

如果没有,任何人都可以使用 sql 指出我正确的方向吗?

或者:

0 投票
2 回答
417 浏览

mysql - 这是 MySQL 中更新查询的正确方法吗?

我在查找 php/mysql 应用程序中的错误时遇到了一些问题,我想知道我是否可以执行以下操作:UPDATE table SET userid='2' WHERE userid='1'-> 我可以更新我在 WHERE 中声明的内容吗?