I am a simple Senior Oracle DBA Consultant....

Oracle Certified (Database 9i/10g/11g
& Application 11i), dynamic, self-motivated and results-oriented
professional with over 16 years of broad- based experience in Database
Management, Administration, Backup & Recovery, Tuning and Oracle
Application Concepts and Architecture using Oracle Technologies (Database,
Oracle Application and Middleware). Expertise in high-technology time and cost
based solutions, quality customer service and commitment to excellence.

Monday, June 24, 2013

Modify table with few additional columns with not null constraint and default value

There was a new requirement to add few columns to a big table (few gigs in size) with not null constraints and default value.

The developer came up with a script and asked me to review,

alter table T1 add F1 varchar2(10);
alter table T1 add F2 varchar2(10);
alter table T1 add F3 varchar2(10);

update T1 set F1=' ',F2=' ',F3=' ';


alter table T1 modify F1 not null;
alter table T1 modify F2 not null;
alter table T1 modify F3 not null;



Oracle has fantastic feature to do all the above steps in one go ....:()   Here you go....

alter table T1 add (F1 varchar2(10) default ' ' not null, F2 varchar2(10) default ' ' not null, F3 varchar2(10) default ' ' not null);

The above DDL ran faster and easy to manage it.

No comments:

Post a Comment