View previous topic :: View next topic
|
Author |
Message |
guruji Warnings : 1 New User
Joined: 13 Apr 2007 Posts: 59 Location: Chennai
|
|
|
|
Hi,
How can we logically delete data from a DB2 table?Could you please explain the same with an example?What is the difference between a logical delete & a physical delete? Could you suggest any links from where I can collect the same data?
Thanking you,
Reni |
|
Back to top |
|
|
mkk157
Active User
Joined: 17 May 2006 Posts: 310
|
|
|
|
Physical Delete:
Physically removes the data from the DB2 Table. We can achieve this by DELETE statement.
We can delete the data from a DB2 table by specifying a predicate, then the rows that satisfies the predicate are physically removed from the DB2 table.
Logical Delete:
Here in this case, the data is not actually removed, instead, it marks it with the special delete status. i.e. logical deleiton. We can achieve this by UPDATE statement.
We can update data in the DB2 table by specisying the predicate in the UPDATE statement, then the rows that satisfies the predicate are logically removed and replaced by the new data. |
|
Back to top |
|
|
guruji Warnings : 1 New User
Joined: 13 Apr 2007 Posts: 59 Location: Chennai
|
|
|
|
Hi,
Got an idea about the logical delete. But can you please provide an example on how to make it happen on a DB?
Also can you provide some links from where I can get a clear idea about the same?
Thanks,
Reni |
|
Back to top |
|
|
mkk157
Active User
Joined: 17 May 2006 Posts: 310
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Database engines typically do not provide/support a logical delete (and IMHO do not need one) - when you specify DELETE, that entry is gone. When you specify UPDATE, that entry is changed. There is no "deleted" indicator at the databse level that can be checked to determine if a row has been logically deleted.
There are a few applications that work this way, but the function is application dependent. |
|
Back to top |
|
|
mkk157
Active User
Joined: 17 May 2006 Posts: 310
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello M K K,
Not to worry I didn't read your reply as an argument and even if so, sometimes arguments/discussions help make things more clear.
I believe an answer is in the first few lines at that link
Quote: |
An application can support one of the following types of delete operations:
Physical delete--Data is physically deleted from the database.
Logical delete--A status column in a database entity is set to an inactive or invalid status, but the data is not deleted from the database.
|
Notice that the first sentence mentions that an application can support this (not the database system). In the logical delete, notice that a status column needs to be added and managed by the code rather than the dbms.
This does not mean that either is better than the other. Whether "this" must be sync'ed with "something else" may need consideration.
I'd recomend that the entire application and interactions with others be considered and then pick the strategfy that works for the particular case. |
|
Back to top |
|
|
guruji Warnings : 1 New User
Joined: 13 Apr 2007 Posts: 59 Location: Chennai
|
|
|
|
Hi,
Got to understand the handling of logical delete in applications. But still it is not clear that whether the same is applicable to Databases or not.
Regarding the use of UPDATE verb for logical delete, Dick stated that, "When you specify UPDATE, that entry is changed. There is no "deleted" indicator at the databse level that can be checked to determine if a row has been logically deleted.
"
Does it mean that logical delete is not at all possible in Databases?
Could you please make it clear? |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
Note that logical delete must be implemented to ensure that all related tables, SQL, and other code check appropriately for your logical-delete column. This is the designer/programmer's responsibility.
E.g., if you logically delete a parent row, but do nothing about child rows (in another table), they will still be processed by any code that looks at that table. In this case, you would need to logically delete them, and modify their code to check for their logical-delete column as well, or always access them via code that looks at only child records of non-logically-deleted parents. |
|
Back to top |
|
|
guruji Warnings : 1 New User
Joined: 13 Apr 2007 Posts: 59 Location: Chennai
|
|
|
|
Ok Dick,
So you tell that, if a status column is added& managed by the programmer, the logical delete can be made possible on Databases using UPDATE verb, right?
I hope I can follow this. Let me try this out.
Thank you all for sharing your knowledge in this regard.
If any one come to know anything more please share with me in the same link,
Thanks,
Reni |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
You're welcome
As a caution, please keep in mind that if a deleted indicator is added to the tables, then every query or bit of procesing logic must check if the currently retrieved data is good or if it has been "deleted". Also, keep in mind that if this indicator is used, checking for a "not on file" takes on a new meaning - the sql return code is no longer sufficient to detect a "not on file".
Unless there is some very pressing reason to do so, i'd not recommend using a "deleted indicator" - FWIW. |
|
Back to top |
|
|
|