How can I drop a “not null” constraint in Oracle when I don't know the name of the constraint?

前端 未结 7 1135
花落未央
花落未央 2020-12-07 20:10

I have a database which has a NOT NULL constraint on a field, and I want to remove this constraint. The complicating factor is that this constraint has a system-defined nam

7条回答
  •  失恋的感觉
    2020-12-07 20:45

    Something like that happened to me when I made copies of structures to temporary tables, so I removed the not null.

    DECLARE
       CURSOR cur_temp_not_null IS
            SELECT table_name, constraint_name  FROM all_constraints WHERE table_name LIKE 'TEMP_%' AND  owner='myUSUARIO';
    
       V_sql VARCHAR2(200); 
    
    BEGIN
      FOR c_not_null IN cur_temp_not_null
       LOOP
         v_sql :='ALTER TABLE ' || c_not_null.table_name || ' DROP CONSTRAINT '|| c_not_null.constraint_name;
         EXECUTE IMMEDIATE  v_sql;     
      END LOOP;
    END;
    

提交回复
热议问题