Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 
 Home
 E-mail Us
 Oracle Articles
New Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB  

Don Burleson Blog 


 

 

 


 

 

 
 

Oracle Column Default Value Tips

Expert Oracle Database Tips by Donald BurlesonMarch 25, 2015

 

Question:  Is there an overhead when a add a column default value to a table? 

I want to know the consequences of adding a DEFAULT value to an existing column in a table.

I understand that when you add a DEFAULT value to a column which is Nullable, Oracle updates all the NULL values for the column to the DEFAULT value, generating a lot of undo/redo data.

Is adding a DEFAULT value to a NOT NULL column a problem?

As the column is NOT NULL, an update would not be done, so no undo/redo data will be generated.

Answer:  I can think of only one case where modifying a table column default value could cause all rows to be changed.  

However, if you were to simultaneously alter the table to allow NOT NULL and a default, then yes, Oracle might perform a full-table scan to change all NULL rows.  

Try this, and see if it updates the table:

alter table
    fred
modify (mycol NOT NULL default ?EMPTY?);

However, I would prefer to use ordinary DML updates . . .

Obviously, this relationship cannot be enforced if you leave "orphan" appointments, which are not hooked to a patient.

Update fred set mycol = ?EMPTY? where mycol is NULL;

alter table
    fred
modify (mycol NOT NULL);

Otherwise, setting a column default would never be retroactive, only applying to new inserts and updates.  

Here are the table column default options, used to set column default values in CREATE TABLE and ALTER TABLE MODIFY commands:

CREATE|ALTER TABLE <table name>
( { <column name> <data type> [ DEFAULT <default> ]) . . . .

At table creation time, adding a column default creates no overhead at all:

create table t1 (id number default (0));

A column default is rarely changed at alter table time, but there are issues with NULL values and default values.  

When you add a DEFAULT value to a column which is Nullable, Oracle recognizes a NULL as a legitimate existing value and will not make any updates.  

Some people will deploy insert triggers to fill-in default values . . .  

Also, beware that Create Table As Select (CTAS) can have issues with default column values.

Steve Callan points out that Oracle 11g has a New Feature for the DEFAULT clause for a NOT NULL column:

"When you add a column, the initial value of each row for the new column is null. If you specify the DEFAULT clause for a NOT NULL column, then the default value is stored as metadata but the column itself is not populated with data. However, subsequent queries that specify the new column are rewritten so that the default value is returned in the result set.

This optimized behavior differs from earlier releases, when as part of the ALTER TABLE operation Oracle Database updated each row in the newly created column with the default value, and then fired any AFTER UPDATE triggers defined on the table."

 
Get the Complete
Oracle SQL Tuning Information 

The landmark book "Advanced Oracle SQL Tuning  The Definitive Reference"  is filled with valuable information on Oracle SQL Tuning. This book includes scripts and tools to hypercharge Oracle 11g performance and you can buy it for 30% off directly from the publisher.

 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  

and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright © 1996 -  2020

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.

 

 

��  
 
 
Oracle Training at Sea
 
 
 
 
oracle dba poster
 

 
Follow us on Twitter 
 
Oracle performance tuning software 
 
Oracle Linux poster