0

Is there a way to give names to already existing constraints?
for example :

create table employee (emp_id number(10),emp_name varchar2(20),
dept_id number(10),foreign key(dept_id) references department(dept_id));

In the above query I haven't named the foreign key constraint so after the creation of the table can I give a name to it also can the foreign key constraint be dropped without dropping the column??

2 Answers 2

4

Yes you can rename a constraint like this: alter table t rename constraint old_name to new_name

Edit: I've forgotten about the second question. Yes you can drop a constraint without dropping the column. If you do not know the name of the constraint you can find it in user_constraints table like this:

select constraint_name from user_constraints where table_name = 'your_table' and constraint_type ='R'

Sign up to request clarification or add additional context in comments.

Comments

2

For the second part, yes you can drop the foreign key constraint.

3 Comments

without a name and without having to drop the column?
Alter table table_name drop constraint constraint_name
No, You can't drop it when you haven't specified any name unless you know the system specified constraint name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.