简体   繁体   English

SQL Server:更新大号时的警报。 的行

[英]SQL Server: Alert when updating large no. of rows

Today I f*ed up the most important table on my company's website. 今天我在我公司的网站上找到了最重要的表格。 I forgot to add the where clause after an update statement and the login for all the users were changed. 我忘了在更新语句后添加where子句,并且更改了所有用户的登录名。 About 13,000 to be aprrox. 大约13,000个是aprrox。

Is there a way in SQL Server or SQL Server Management Studio to give an alert if an update or delete is made for say, more than 10 rows? 如果对超过10行进行更新或删除,SQL Server或SQL Server Management Studio中是否有一种方法可以发出警报?

This is a slightly different approach, but if you want to be alerted to the fact that you're using a production server, SSMS Tools Pack (a free add-in for SSMS) has a nifty feature called Window Connection Colouring . 这是一种略有不同的方法,但如果您想要提醒您使用生产服务器这一事实, SSMS工具包SSMS的免费插件)有一个很棒的功能,称为窗口连接着色

You associate each SQL Server you use with a colour, and each query window has a corresponding coloured bar at the top. 您将使用的每个SQL Server与颜色相关联,并且每个查询窗口顶部都有对应的彩色条。 All my production servers are red; 我的所有生产服务器都是红色的 dev are green; 开发者是绿色的; and test/staging are orange. 和测试/分期是橙色的。 It's always quite apparent to me when I need to be careful. 当我需要小心时,对我来说总是很明显。

Also, by default, every new query window opens with a BEGIN TRAN / ROLLBACK statement so you remember to test potentially damaging queries first. 此外,默认情况下,每个新的查询窗口都会打开一个BEGIN TRAN / ROLLBACK语句,因此您要记住首先测试潜在的破坏性查询。

Note I have no commercial interest in the software, but I have found it very useful. 注意我对该软件没有任何商业兴趣,但我发现它非常有用。

You could add an on update trigger that fails when the inserted table has above X number of rows, though then later if you really did want to make the change you'll need to disable/renable the trigger (not hard, but annoying - which is what you're after, I suppose). 您可以添加一个更新后的触发器,当插入的表格超过X行数时会失败,但是如果您真的想要进行更改,则需要禁用/重新设置触发器(不是很难,但很烦人 - 哪个我猜想,这就是你所追求的。

But yes, if you're doing things manually they should be in a begin tran / rollback transaction with a select at the end to verify what you were doing, and only after you're happy with it then commit it. 但是,是的,如果你手动做事,他们应该在一个开始转发/回滚事务中,最后用一个选择来验证你在做什么,并且只有在你满意之后再提交它。 (We can probably all tell you of at least one case where we thought we were happy with it and still committed it incorrectly, though - haha). (我们可能都会告诉你至少有一个案例,我们认为我们对此感到满意并且仍然错误地承诺了 - 哈哈)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 拿到 SQL Server Reporting Services中存储过程返回的行数 - Get no. of rows returned by stored procedure in SQL Server Reporting Services 在SQL Server中更新单个表的行时防止死锁 - Prevent Deadlock when updating rows of a single table in SQL Server 用于转换编号的 SQL 查询。 行数为否。 oracle中的列 - SQL query to convert no. of rows to no. of column in oracle 使用SQL Server 2005 Management Studio的csv没有。 在csv的末尾添加的导出行数 - csv using sql server 2005 management studio without the no. of exported rows being added at the end of the csv SQL SERVER-INSERT INTO .. SELECT ..结果不同。 的行数比在SELECT ..本身中插入的行数 - SQL SERVER - INSERT INTO.. SELECT.. results in different no. of rows inserted than in SELECT.. itself SQL Server删除大量行 - SQL server delete large number of rows Python API 拉到 SQL 服务器(更新行) - Python API pull to SQL Server (Updating rows) SQL Server:更新同一表中具有依赖项的行 - SQL Server: Updating rows with dependencies in the same table 访问大量行和数据时,SQL Server GUI保持冻结 - SQL Server GUI keeps freezing when accessing large amount of rows and data 使用 Propel 2 更新行时使用 SQL 函数 - Using an SQL function when updating rows with Propel 2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM