How to ADD a CONSTRAINT NAME to an already EXISTING CONSTRAINT(如何将约束名称添加到已经存在的约束)
问题描述
有没有办法为已经存在的约束命名?
例如:
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 重命名约束 old_name 为 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:
选择约束名称来自 user_constraints其中 table_name = 'your_table'和constraint_type ='R'
这篇关于如何将约束名称添加到已经存在的约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将约束名称添加到已经存在的约束
基础教程推荐
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 无法解决整理冲突 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
