Objective
Time too fast, self-graduation has been more than three years, has been engaged in work for three year. Then from the development to the present, the data on the things are very little, some of the optimization of the data script has not been to understand, just keep writing code. Recently I think it is the database seriously understand, and recently I have been learning the front-end knowledge, as well as the Java language, in fact, the database is also the most heavy ah. So today opened a new page, just see the transaction and lock this chapter, read, summed up I think the effect will be better, I hope to communicate with you .....
Body
Exclusive lock
The window one executes a transaction, but does not commit. Next we do the following in window two.
I have limited the five-second query time, more than five seconds after the following prompt such words. It is because of the exclusive lock, because the exclusive lock is occupied alone, since I have been in this room, you will not allow other people to come in to occupy. I think it can also be understood as an independent toilet, if I occupy the toilet, in time I do not defecate, I will occupy, then you other people need in time and no way.
Shared locks
Read does not read the shared lock is related to the level of isolation, the level of isolation is divided into READ UNCOMMITTED uncommitted, Read committed has been submitted this is the default value so when we say exclusive lock Windows two query data, REPEATABLE read REPEATABLE READ , serializable serializable, snapshot snapshots, and read Committed snapshot have been committed for reading isolation.
Set Transaction isolation level read UNCOMMITTED; Used to set the isolation levels at the time of the query, level name, if the above exclusive lock example, in the window to change the second change so I can read the data.
Wow so happy ah, finally read it. Unfortunately, here we have designed a term that is dirty to read. That is, when we do not commit the transaction, we go through some means to read the modified data this process is dirty read, if my transaction rollback, then you this data is not the real data. How to prevent dirty reading, then we say the exclusive lock is the time, the default isolation level is the second, that is, to prevent dirty read the lowest level. That is, you have to get a shared lock, so read UNCOMMITTED is saying that there is no access to the shared lock, so he can find data that is dirty data is incorrect.
For what is a shared lock, I think it is the shared lock that is used to perform the task at query time, the transaction share lock executed under the Serialation isolation level is persisted to the transaction commit, and is not allowed to be inserted when not committed. Then I see 2008 Technology insider said only at this level is can be inserted, but I sql2012 on the implementation of the serialation level is not possible, as for the Phantom is not allowed, it is possible that 2012 has been modified it. Then the query does not matter, I feel is because of shared locks, are used to query, then everyone can. Just like a public restroom, you can go in, I can go in.
The basic is this two locks, and then the next is the high-level lock, update, intent, architecture lock.
Update lock
BEGIN Tran
SELECT * from WebSiteInfo.dbo.BookPlan with (updlock) where bookname= ' 1 '
WAITFOR DELAY ' 00:00:10 '
Insert WebSiteInfo.dbo.UserInfo (Name) VALUES (' Niubi ');
Commit Tran
The update lock is simply an understanding of the locks placed on updatable resources such as rows, pages, and tables. Update locks are used to prevent common forms of deadlocks that occur when multiple sessions lock resources and may later update resources when this is the given definition. Just say that my update is only for my current operation plus lock instead of locking the entire table.
Intent lock, the architecture has not yet understood that there is something to do, write it here .....
Summarize
Set foot on this road, no regrets, there are many things to learn, to become a qualified programmer is still very far away.
If every day isn't easy, it'll be easier for a day, and if it's easier for each day, it'll isn't being easy for a day.
Simple Understanding Lock