troubleshooting Question

Need to write script in such way they will produce the same result even if run multiple times

Avatar of YBSolutions
YBSolutionsFlag for Argentina asked on
Oracle Database
28 Comments3 Solutions725 ViewsLast Modified:
Hi,

We are doing development to meet a big requirement.
Therefore, keep on doing the below type of tasks ( and many more ) every now and than.

a. Add/Drop a table.
b. Add/Drop a constraint.
c. Add/Drop a column
d. Changing a column from null to not null and vice-versa.

Because of development team size and nature, everything can't be checked manually.

In the given situation:
We want to write the program in such a way if a script is run multiple times.
It should do the same thing.
==========

My question is:

How to write the code to avoid the below errors (errors free) if same script is run multiple times.
Notes:  1. We got below errors while running the same script 2nd time.
              2. Below is excerpt from the log file (not the full log).

SQL>
SQL> ALTER TABLE Table_name RENAME CONSTRAINT  TESTPROFILE_PAXWTTABLE_FK TO  TESTPROF_PAXWTTABLE_FK ;
ALTER TABLE Table_name RENAME CONSTRAINT  TESTPROFILE_PAXWTTABLE_FK TO  TESTPROF_PAXWTTABLE_FK
*
ERROR at line 1:
ORA-23292: The constraint does not exist


SQL>
SQL> DROP INDEX TESTPROFILE_UPLIFTCONFIGWB_FK;
DROP INDEX TESTPROFILE_UPLIFTCONFIGWB_FK
           *
ERROR at line 1:
ORA-01418: specified index does not exist


SQL>
SQL>  CREATE INDEX TESTPROF_UPLIFTCONFIGWB_FK    ON Table_name (UPLIFT_CONFIG_ID)
  2   INITRANS 17
  3          TABLESPACE tablespace_name
  4  ;
 CREATE INDEX TESTPROF_UPLIFTCONFIGWB_FK    ON Table_name (UPLIFT_CONFIG_ID)
              *
ERROR at line 1:
ORA-00955: name is already used by an existing object


SQL>
SQL> ALTER TABLE Table_name RENAME CONSTRAINT  TESTPROFILE_UPLIFTCONFIGWB_FK TO  TESTPROF_UPLIFTCONFIGWB_FK ;
ALTER TABLE Table_name RENAME CONSTRAINT  TESTPROFILE_UPLIFTCONFIGWB_FK TO  TESTPROF_UPLIFTCONFIGWB_FK
*
ERROR at line 1:
ORA-23292: The constraint does not exist
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 3 Answers and 28 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 28 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros