ailon's DevBlog: Development related stuff in my life

ON DELETE SET NULL

10/13/2007 4:44:12 PM

I've just discovered the existence of SET NULL option for ON DELETE/ON UPDATE clauses in Oracle. Yes, I'm stupid. No idea in which version this first appeared but there's still no way to set this through GUI in Enterprise Manager Console (as far as I know). However you can set this through code or via GUI in Oracle SQL Developer.

This could be very handy when you have some columns referencing other tables but the data in this columns is of not critical importance. For instance you may have user id of the person who last edited some article stored in the table but if you delete the user (and you are sure about this) you don't want that value preventing your operation. Earlier I just didn't create foreign key on such fields, resulting in ghost values. Now I can just add ON DELETE SET NULL to foreign key declaration and the problem is solved.

Btw, this is also available in MS SQL Server 2005 (not in 2000) along with SET DEFAULT. I can hardly think what is the possible use for SET DEFAULT. Hard-coding the value for referenced field!? Doesn't sound very useful to me. But who am I? If it's there then probably someone needs it.

Tags: , , ,

blog comments powered by Disqus
Copyright © 2003 - 2012 Alan Mendelevich
Powered by BlogEngine.NET 2.5.0.6