Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
40
Добавлен:
16.04.2013
Размер:
4.96 Mб
Скачать

Dropping Integrity Constraints

prompt Enter table name to find its primary key: accept table_name

select constraint_name from user_constraints where table_name = upper(’&table_name.’) and constraint_type = ’P’;

prompt Enter new name for its primary key: accept new_constraint

set serveroutput on

declare

--USER_CONSTRAINTS.CONSTRAINT_NAME is declared as VARCHAR2(30).

--Using %TYPE here protects us if the length changes in a future release.

constraint_name user_constraints.constraint_name%type; begin

select constraint_name into constraint_name from user_constraints where table_name = upper(’&table_name.’)

and constraint_type = ’P’;

dbms_output.put_line(’The primary key for ’ || upper(’&table_name.’) || ’ is:

|| constraint_name);

execute immediate

’alter table &table_name. rename constraint ’ || constraint_name || ’ to &new_constraint.’;

end;

/

Dropping Integrity Constraints

Drop an integrity constraint if the rule that it enforces is no longer true or if the constraint is no longer needed. Drop an integrity constraint using the ALTER TABLE command and the DROP clause. For example, the following statements drop integrity constraints:

ALTER TABLE Dept_tab

DROP UNIQUE (Dname);

ALTER TABLE Dept_tab

DROP UNIQUE (Loc);

ALTER TABLE Emp_tab

Maintaining Data Integrity Through Constraints 3-25

Соседние файлы в папке Oracle 10g