How to lock records in a table?
Submitted by: AdministratorWhile there shouldn't be many reasons to do this in MGA database system like Firebird, there are ways to do it.
One is to use a dummy update for all the records you wish to lock. Many developers do this by accident and get the deadlocks. Example that locks employee 8:
-- start transaction
update employee set emp_no = emp_no where emp_no = 8;
...
update employee set ... where emp_no = 8;
-- end transaction
A more elegant way is to use the SELECT ... WITH LOCK syntax.
-- start transaction
select * from employee where emp_no = 8 WITH LOCK;
...
update employee set ... where emp_no = 8;
-- end transaction
Please note that locking easily leads to deadlocks with NO WAIT and application hanging with WAIT transactions. Use it only if you're really sure you know what you are doing and why.
Submitted by: Administrator
One is to use a dummy update for all the records you wish to lock. Many developers do this by accident and get the deadlocks. Example that locks employee 8:
-- start transaction
update employee set emp_no = emp_no where emp_no = 8;
...
update employee set ... where emp_no = 8;
-- end transaction
A more elegant way is to use the SELECT ... WITH LOCK syntax.
-- start transaction
select * from employee where emp_no = 8 WITH LOCK;
...
update employee set ... where emp_no = 8;
-- end transaction
Please note that locking easily leads to deadlocks with NO WAIT and application hanging with WAIT transactions. Use it only if you're really sure you know what you are doing and why.
Submitted by: Administrator
Read Online Firebird Job Interview Questions And Answers
Top Firebird Questions
☺ | How to detect the server version? |
☺ | How to write UDF s in Delphi? |
☺ | How do convert or display the date or time as string? |
☺ | How to drop all foreign keys in database? |
☺ | Is there some bulk load or other way to import a lot of data fast? |
Top Databases Programming Categories
☺ | RDBMS Interview Questions. |
☺ | SQL Interview Questions. |
☺ | SSRS Interview Questions. |
☺ | Database Administrator (DBA) Interview Questions. |
☺ | Sybase Interview Questions. |