Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8478599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:47:24+00:00 2026-06-10T18:47:24+00:00

So, we just found out that 254 tables in our Oracle DBMS have one

  • 0

So, we just found out that 254 tables in our Oracle DBMS have one column named “Foo” with the wrong length- Number(10) instead of Number(3).

That foo column is a part from the PK of the tables.
Those tables have other tables with forigen keys to it.

What I did is:

  1. backed-up the table with a temp table.
  2. Disabled the forigen keys to the table.
  3. Disabled the PK with the foo column.
  4. Nulled the foo column for all the rows.
  5. Restored all the above

But now we found out it’s not just couple of tables but 254 tables.

Is there an easy way, (or at least easier than this) to alter the columns length?

P.S. I have DBA permissions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:47:25+00:00Added an answer on June 10, 2026 at 6:47 pm

    There’s an easier way to generate the scripts that you want, use the system tables user_tables and user_constraints to dynamically generate the DDL. The downside is that this requires downtime. Also note that I use the truncate command rather than delete, which should be faster.

    Assuming a simple table that looks like:

    create table a ( 
       foo number(10)
     , bar number(10)
     , constraint pk_a primary key (foo)
     , constraint fk_a foreign key ( bar ) references a(foo )
      );
    

    This unlovely looking query

    select cmd
      from ( 
    select table_name
         , 1 as stage -- Just used to order by at the end.
         , 'create table ' || table_name || '_backup as select * from ' 
                          || table_name || ';' || chr(10) as cmd
           -- chr(10) is LF
      from user_tab_columns -- View of all columns
     where column_name = 'FOO'
       and data_precision = 10 -- Length of the number
     union all
    select table_name
         , 3 as stage
         ,  'truncate table ' || table_name || ';' || chr(10) -- Remove all data
           || 'alter table ' || table_name 
                   || ' modify ( foo number(3));' || chr(10)
           || 'insert into ' || table_name || ' select * from ' 
                || table_name || '_backup;' || chr(10)
           || 'drop table ' || table_name || '_backup;' as cmd
      from user_tab_columns
     where column_name = 'FOO'
       and data_precision = 10
     union all
    select ut.table_name
         , 2 as stage
           -- Disable the constraint
         , 'alter table ' || uc.table_name || ' disable constraint ' 
                || uc.constraint_name || ';' || chr(10) as cmd
      from user_constraints uc -- All named constraints
      join user_tab_columns ut
        on uc.table_name = ut.table_name
     where ut.column_name = 'FOO'
       and ut.data_precision = 10 
       and constraint_type = 'R' -- Foreign Key constraints (see link)
     union all
    select ut.table_name
         , 4 as stage
         , 'alter table ' || uc.table_name || ' enable constraint ' 
              || uc.constraint_name || ';' || chr(10) as cmd
      from user_constraints uc
      join user_tab_columns ut
        on uc.table_name = ut.table_name
     where ut.column_name = 'FOO'
       and ut.data_precision = 10
       and constraint_type = 'R'
           )
     order by stage
    

    Will produce the following:

    create table A_backup as select * from A; -- Create your backup
    alter table A disable constraint FK_A; -- Disable FKs
    truncate table A; -- Remove all data in the table
    alter table A modify ( foo number(3)); -- Reduce the size of the column
    insert into A select * from A_backup; -- Replace all the data
    drop table A_backup; -- Drop the backup
    alter table A enable constraint FK_A; -- Re-enable FKs
    

    Due to the column stage, this won’t be done table by table but stage by stage so that all the constraints will be disabled at the same time, which will avoid problems. If you’re scared (I would be) then remove the drop of the _backup tables from the query; this means that whatever goes wrong you’re safe.

    If you’re running this in SQL*Plus you also want to include whenever sqlerror exit so that if there’s a problem, for instance no more tablespace, you don’t truncate things that you haven’t backed-up. It might almost be worth running it stage by stage so that you know that everything has completed correctly.

    I would suggest testing this on a different user with a few tables to ensure that it does everything you need.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this sp. I just found out that M.MDS_FILE column, contains a file
I have an interview tomorrow morning and just found out that I will also
Just have read sass changelog and found out that FSSM (the gem that had
I've just found out that a spammer is sending email from our domain name,
I have a master-master replication setup and just found out that sometime during the
To my surprise I just found out that applying text-alignment to a table column
Ok, just found out that using DEFAULT_GUI_FONT is the wrong thing to actually use
Just found out that this site uses tables for layouts. Does anyone find this
Just found out that when I pressed up in my cmd one of my
I have just found out that Apache Tomcat cannot run as a Windows service

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.