Home > Enterprise >  How to avoid Ctrl-E execute accidents with SQL Server?
How to avoid Ctrl-E execute accidents with SQL Server?

Time:10-09

SQL Server Management Studio executes the entire script after Ctrl-E is pressed.

For manual maintenance script files, I have been commenting out all UPDATE, INSERT and DELETE statements.

Execution is then only done by a selecting the SQL script to execute.

Are there other ways to avoid Ctrl-E execute accidents?

CodePudding user response:

In SQL Server Management Studio you can remove the shortcut CTRL E to execute a query.

Go to Tools > Options in the menu, then go to Environment > Keyboard > Keyboard in the tree on the left. Then select Query.Execute in the right table. Select the shortcut CTRL E (SQL Query Editor) then click Remove which removes the shortcut. You will then no longer be able to execute the query when clicking CTRL E.

enter image description here

CodePudding user response:

To prevent executing an entire script file from start to end, and only allow running selected snippets, this would work:

WHILE 1=1
  PRINT 'NOT ALLOWED, press the STOP button'

PRINT 'After WHILE, will not show unless executed manually'

GO

PRINT 'After GO, will not show unless executed manually'

Because the server goes into very busy loop, it may not immediately stop when you click the STOP button, but it will stop in the end.

For sake of completeness, here is the STOP button:

enter image description here

  • Related