In T-SQL this can be achieved by using proper level of transaction isolation and in certain cases applying specific lock hints in DML operations. However, I suggest to leave it to SQL Server, as it has its own mechanism to prevent such situations and using locks incorrectly can lead to blocking and deadlocks.
I know a good artcile (there is also a great book by the same author called 'Defensive Programming in SQL Server')
Developing Modifications that Survive ConcurrencyIt's rather long, but a very good reading.
>I want to introduce some form of locking (or alternative if locking is not best practise) to ensure that Two users dont update same Table/Tables at the same time.
>
>I have the following VFP code which has worked fine .... would be interested on how this would be coded in TSql
>
>Do while .T.
> Sele MyAlias
> If Flock()
> && Do some processing which needs exclusive use of the table
> Sele MyAlias
> Replace MyField with MyValue Or Append Blank and Replace etc depending on circumstances
> Unlock
> Exit
> Else
> Wait Window "Please wait ... waiting to Lock MyAlias" Nowait
> Endif
>Enddo
>Wait Clear
>
>Would be interested on what code is required to replicate the above functionality in TSql or C#
>
>Tia
>Gerard
If it's not broken, fix it until it is.
My Blog