0

This question is combination of super user and DBadmins.

It happened before that I ran some transaction on Database and was called out to meeting. This transaction then caused locks for other developers.

Even worse case scenarios, locked computer over weekend.

1) Is there a way to run a script on Windows lock screen? 2) Is there a script that would check if I have any locks in database in any Microsoft SQL server studio tab?

Zikato
  • 536
  • 9
  • 18
  • Do you really need to keep transactions in the first place? The usual approach on MS SQL is to rollback or commit the transactions either per-statement (autocommit) or per-batch. – Luaan Mar 27 '17 at 11:47
  • I'm talking about hundreds of inserts into 10 different tables. It takes some time to check if they are correct and I might forget that I have opened transaction on different tab. – Zikato Mar 27 '17 at 13:30

1 Answers1

0

There are ways to find locks and kill such processes, but it's impossible to determine whether those processes are "legit" or if they belong to someone that has left their workstation.

There's some info on using sp_who2and sp_lockin this thread: How to find what is locking my tables

Community
  • 1
  • 1
  • I'm talking about locks caused by me. I know I can check them from withing SQL, but I'm wondering if I can check them from Windows script. And if I can run this check script whenever I try to lock my stations. – Zikato Mar 27 '17 at 13:31
  • Did you try `sp_who2`and `sp_lock`? In there you'll find info about which user that runs the respective processes. Still - there's no way to determine whether something is legit or not. You locking your workstation is not the equivalent to "I should have all processes killed" - right? – Patrik Birgersson Mar 27 '17 at 16:50