Q
Problem solve Get help with specific problems with your technologies, process and projects.

Locking a record, not the whole table

I would like to ask you how I can lock a record and not the complete table. I assigned a predefined number to an invoice, but I got duplicate numbers if two people at the same time want that invoice. I read that I could use the for update at the end of SQL statement but I am not sure:

 Select xx from yy where zz=zx for update

The SELECT FOR UPDATE will get data from a table, and then lock the rows that are returned so that you can update them. Once you commit or rollback, your lock is released. For instance:

SELECT empno 
FROM emp
WHERE emp_name='John Q'
FOR UPDATE;
The row(s) returned is now locked by your session. Other sessions will be able to see this row, but not update it. You will be able to modify this row and then commit or rollback to release the lock.

For More Information


Dig Deeper on Oracle database design and architecture

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchHRSoftware

Close