We’re using SQL Server 2000 Query Analyser, and one issue we have is that very occasionally, when a user is updating our live database, they insert the incorrect/no(!) where clause. I know, not good, but it happens.
Are there any editors that will warn of the number of rows that might be changed (if that is even possible) or even a way to configure an editor, if it is connected to a certain database, to prompt for confirmation before the query is run?
We have a way to recover our data in the cases where we run an incorrect query, but it takes time, and I’m just seeing if there are any ways to catch the error, or at least give the user a second chance.
Thanks in advance.
The only way is to not to let user edit data using SQL Server 2000 Query Analyser! But then you’ll have to write an application and control the data, and you can then issue warnings as necessary.
Short of that, you could add triggers to every table and set some sort limit where you issue a ROLLBACK if the rows affected is greater than X. You could even use something like SUSER_NAME() to apply the limit to certain users.
sample trigger:
to automatically generate all the triggers scripts run this (does not actually add them in the database, just produce the text script which you should edit and then run):
all tables will have an affected row limit of 5 unless you login as user “AwesomeSA”. The above script will generate the code, not actually create the triggers. You can edit the output of this script, setting good row limits, users, etc. and then run that script and then the triggers will be created.