please help me in such a stiuation
I have a stored procedure that insert a new record after checking that this record does not exist....
TODO: I need to lock the row after the select statment executed on a specific row to ensure that no changes will occure between
SELECT statment and INsert statment
@RecordExist as int = 0
SELECT @RecordExist = COUNT(*) FROM TABLE where Condition
-- TODO: I need to lock the rows ??
IF @recordExist = 0
print 'Record Exist'
The case that if 2 users execute the stored procedure at same time
both will get that record doesnot exist (after select statment)
and thus it will be added twice :S.
Can a select statment be a transaction, i know that transactoin occured after update/delete/insert ... but can it be from SELECT
Thanks u in advance