TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Best Practices to run update queries on production DB

3 点作者 xeonax超过 1 年前
I am in a new role where I would be sometimes (rarely) required to run update queries on a production DBs. The Tables mostly have 1000 to 10000 rows.<p>I might be required to update 1 to few rows those times. I am not a SQL expert, but know a bit of it.<p>Generally I expect, I would need to create a SELECT query first to identify the rows that I need to modify. SELECT query should exactly return the rows that need modifications, nothing more.<p>Then create an update query using the where clause above. I was thinking of wrapping the update query in transaction and running the statements sequentially, while keeping track of no of rows modified, as well confirming the changes using SELECT query. like below:<p>BEGIN TRANSACTION t1; UPDATE tablename SET attr1=&#x27;attr1&#x27;, attr2=&#x27;attr2&#x27; WHERE Attr3=&#x27;attr3&#x27; AND ID=&#x27;10&#x27;; -- At this point no of rows modified should match the number of rows returned by our previous SELECT query SELECT * from tablename where WHERE Attr3=&#x27;attr3&#x27; AND ID=&#x27;10&#x27;; -- Expected modification should be seen here. COMMIT TRANSACTION t1;-- Commit if everything OK till here.<p>I will be using Azure SQL Database Query Editor to run the queries step by step.<p>What else do I need to be mindful about? I don&#x27;t want to be the person who dropped entire customers table.

3 条评论

brodouevencode超过 1 年前
Something to think about: <a href="https:&#x2F;&#x2F;microservices.io&#x2F;patterns&#x2F;data&#x2F;cqrs.html" rel="nofollow noreferrer">https:&#x2F;&#x2F;microservices.io&#x2F;patterns&#x2F;data&#x2F;cqrs.html</a>
pestatije超过 1 年前
Best practice is not to run update queries on production DB<p>Too many things can go wrong...in fact nobody should have permissions to do so...if you think there is a danger the entire customers table might be dropped, backup the DB
PaulHoule超过 1 年前
Have a backup just in case.