I use begin transaction in my stored procedure. I have code that updates data:
UPDATE
employee
SET
name = @name,
surname = @surname
WHERE
empId = @empid;
Does SQL Server do any locking on the row or coloumn that is being updated? If this is not the case, how would I prevent other users from doing another update while there is a current update in progress? It doeesn’t have to be in the stored procedure, C# is also an option.
SQL Server does issue locks against the objects being accessed – and locking gets pretty complex in terms of what is happening under the covers.
For your specific update statement, assuming a single row is being updated.
Row : Update Lock to gain access to Update the data which then converts to an Exclusive Lock when the data is modified.
Page : Intent Update, which converts to an Intent Exclusive when the data is modified.
There are a lot of details about the locking modes on the MS site : http://msdn.microsoft.com/en-us/library/ms175519(v=sql.100).aspx