Skip to main content

Posts

Showing posts with the label Lock

Difference between Lock and Nolock

Lock Lock in  MSSQL is used to prevent concurrent access of tables. It is widely used to application that have large number of users who access database. In case if a user tries to alter a table the table will be in lock state so that no other user can try to alter the table until the lock release.  In this case User 1 is trying to alter the table in database. User 2 has to wait until the lock is released by user 1. After that User 2 will put lock and execute the query. In case if user fails to use lock it will results in error Note: Lock is used in DML statement. Nolock  Nolock is used so that two or more user can access the table simultaneously.It widely used in DDL statement.    This is many number of user can select (View) data from table. select statement is similar to read. Where as DML is similar to write. By using nolock the data retrieval speed is increased for the user. There is no need wait until other user data selection ends.