oracle笔记 唯一性约束 (转)

本文介绍了如何使用SQL语句在数据库表中创建、修改唯一性约束。包括添加唯一性约束的方法,以及如何删除、重命名和禁用或启用这些约束。

一、创建唯一性约束:

alter table 表名 add constraint 约束名称 unique (列名1、列名2..)
查表:
SQL> desc customer;
Name Type Nullable Default Comments
---------------- ------------ -------- ------- --------
CUSTOMER_ID NUMBER
CUSTOMER_NAME VARCHAR2(20) Y
CUSTOMER_PHONE VARCHAR2(20) Y
CUSTOMER_ADDRESS VARCHAR2(50) Y
添加唯一性约束:
SQL> alter table customer add constraint unq_customer unique (customer_name,customer_phone);
 
二、修改唯一性约束:
1.删除
alter table customer drop constraint unq_customer;
2.重命名
alter table customer rename constraint unq_customer to unq_cst;
3.禁用、启用
alter table 表名 disable/enable constraint 约束名称;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值