如何将约束名称添加到已经存在的约束中 [英] How to ADD a CONSTRAINT NAME to an already EXISTING CONSTRAINT

查看:102
本文介绍了如何将约束名称添加到已经存在的约束中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法给已经存在的约束命名?
例如:

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??

推荐答案

是的,您可以像这样重命名约束: alter table t rename constraint old_name to new_name

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

我忘记了第二个问题.是的,您可以删除约束而不删除列.如果您不知道约束的名称,可以在user_constraints表中找到它,如下所示:

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'

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

这篇关于如何将约束名称添加到已经存在的约束中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆