Pratically its possible to do the operations which i have mentioned in another thread in single step.
Assume the patient is being discharged from the hospital, then in that case I will have to do two things
1 Update the refcount (decrement by 1).
2 If RefCount becomes 0 that entry should be deleted from the table.
Pratically,
Assume its a BTree, We can search the binary tree with the given name and if the name is found (in this case surely gonna happen), we reduce the associated refcount value (decrement by 1), now at that time itself we can check whether its value has become zero, if yes we can delete that node in O(1) time. Whereas in SQL, even though for updating i reach the given node in the Btree, but then for delete i will again have to reach the given node.
The solution which you gave (delete first, check rowcount, update refcount) also faces this problem, while deleting i will have to search the tree with refcount = 1 and given name, if the refcount is not zero i will again have to search the tree with the given name to update the value of refcount.
I hope this will clear u, what i am expecting.
|