What is a lock and what are its causes?

6

I often come across the term: Table x is with lock . What does it mean and what are its causes?

    
asked by anonymous 19.04.2017 / 21:38

2 answers

3

The SGDB retains the right to manipulate the tables / records according to the queue of operations, that is, it performs locks to guarantee the performance of pending operations (not committees ).

Locks row and lock table:

  • Row Locks
    Prevents any operation in the registry until another operation (update for example) is completed. The SGDB will not allow a read on this line (s) not to display outdated data.

  • Table Locks
    Prevents any changes, including a simple query from being made to the table. Some uncommented operation is still in process by another (or even the same - separated by GO )

Several freezing situations in systems occur because of these locks ;

You can force a query to ignore this flag:

select * from teste with (nolock)
    
19.04.2017 / 22:05
2

In a database, when we execute some DML operation (update, insert, delete) we are locking, that is, we are blocking certain object. This prevents another operation from making a change to the table or record ("line") that we are manipulating.

Lock is something natural, it does exist and we do not usually notice it in normal operations. However, when conflicting, large or unfinished operations are performed, then we can have many objects leased. For simplicity let's imagine the following scenario:

  

Zezinho made an update in the users table, but did not commit, ie, he blocked one or more records, if an application tries to manipulate these locked records, awaits response, the which can result in a crash of this application.

It is worth mentioning that registry lock and table exist.

The above scenario is coarse, but I think it superficially serves to simplify understanding.

I believe the following article is enlightening on the subject: link

p>     
19.04.2017 / 21:45