Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: DROP COLUMN Oracle 7.3
Sorry, no can do in Oracle 7.3. I believe this is coming in Oracle 8.00.??
To do this you have to:
The following is part of a utility package I have that helps with the
dependent constraints. If you don't have a
consistent naming convention for foreign keys, it won't work. If you do, you
can simply change the line,
"R_Pk_Name := UPPER(TableName_in) || '_PK';" to fit your needs. Sorry, I
wrote this one more for my needs
than anything else.
/*
|| NOTE: This procedure will disable or enable DEPENDENT foreign keyEND Set_FK_State; Received on Thu Jun 18 1998 - 23:34:18 CDT
|| constraints for the table specified in TableName_in. It
|| depends on a Primary Key constraint name, wherein the constraint
|| for the primary key consists of the table name + "_PK'.
*/ PROCEDURE Set_FK_State(TableName_in VARCHAR2, State_in VARCHAR2) IS CURSOR FK_Cur(RName VARCHAR2) IS SELECT R_Constraint_Name, Constraint_Name, Table_Name FROM User_Constraints WHERE R_Constraint_Name = RName; FK_Rec FK_Cur%ROWTYPE; Cur_Handle INTEGER; Sql_Stmt VARCHAR2(500); R_Pk_Name VARCHAR2(50); V_Changed INTEGER; Con_Count INTEGER; StateStr VARCHAR2(8); BEGIN R_Pk_Name := UPPER(TableName_in) || '_PK'; IF UPPER(SUBSTR(State_in,1,1)) = 'D' THEN StateStr := 'DISABLE '; ELSE StateStr := 'ENABLE '; END IF; Con_Count := 0; OPEN FK_Cur(R_Pk_Name); Cur_Handle := DBMS_SQL.OPEN_CURSOR; LOOP FETCH FK_Cur INTO FK_Rec; IF FK_Cur%NOTFOUND THEN EXIT; END IF; Sql_Stmt := 'ALTER TABLE ' || FK_Rec.Table_Name || ' ' || StateStr || ' CONSTRAINT ' || FK_Rec.Constraint_Name; DBMS_OUTPUT.PUT_LINE(StateStr || FK_Rec.Constraint_Name || ' for Table: ' || FK_Rec.Table_Name); DBMS_SQL.PARSE(Cur_Handle, Sql_Stmt, DBMS_SQL.V7); V_Changed := DBMS_SQL.EXECUTE(Cur_Handle); Con_Count := Con_Count + 1; END LOOP; DBMS_SQL.CLOSE_CURSOR(Cur_Handle); CLOSE FK_Cur; DBMS_OUTPUT.ENABLE(100000); DBMS_OUTPUT.PUT_LINE(TO_CHAR(Con_Count) || ' dependent constraints were altered.');