You do not have to have that order of operations. You can delete the old constraint and then create the new constraint and it is a perfectly valid set of commands.
CREATE TABLE table_name (
id NUMBER CONSTRAINT constraint_name1 CHECK ( id > 10 )
);
INSERT INTO table_name ( id ) VALUES ( 11 );
ALTER TABLE table_name DROP CONSTRAINT constraint_name1;
ALTER TABLE table_name ADD CONSTRAINT constraint_name2 CHECK ( id > 9 );
db<>fiddle
However, if you drop the constraint without a replacement constraint being in place then there will be a period of time when it is possible that an INSERT
or UPDATE
statement could modify the table so that it contains data that is invalid against the constraint and creation of the new constraint would fail.
CREATE TABLE table_name (
id NUMBER CONSTRAINT constraint_name1 CHECK ( id > 10 )
);
INSERT INTO table_name ( id ) VALUES ( 11 );
ALTER TABLE table_name DROP CONSTRAINT constraint_name1;
INSERT INTO table_name ( id ) VALUES ( 4 );
Then:
ALTER TABLE table_name ADD CONSTRAINT constraint_name2 CHECK ( id > 9 );
Fails with:
ORA-02293: cannot validate (SCHEMA_NAME.CONSTRAINT_NAME2) - check constraint violated
db<>fiddle
Whereas, if you create the new constraint before dropping the old constraint then the invalid data cannot be inserted.