OCP:051-----什么约束在建表的时候会传递?

Oracle支持的约束类型:

         1.UNIQUE

          2.NOT NULL

          3.PRIMARY KEY

           4.FOREIGN KEY

           5.CHECK

 

第一步:建表

SQL> create table customers(cust_id varchar2(10) constraint pk_customer primary key);

Table created.

SQL> create table times(time_id date constraint pk_times primary key);

Table created.

SQL> create table products(prod_id number(6) constraint pk_products primary key);

Table created.

SQL> create table sales(prod_id number(6) constraint fk_sales_prod references products(prod_id),cust_id varchar2(10) constraint fk_sales_cust references customers(cust_id),
  2  time_id date constraint fk_sales_time references times(time_id),order_date date not null,test_uniq number unique,test_check number check(test_check >1));

Table created.

SQL> create table new_sales(prod_id,cust_id,order_date default sysdate,test_uniq,test_check) as select prod_id,cust_id,order_date,test_uniq,test_check from sales;

Table created.

SQL> desc new_sales;
 Name                                                Null?            Type
 ----------------------------------------- --------       ----------------------------
 PROD_ID                                                             NUMBER(6)
 CUST_ID                                                             VARCHAR2(10)
 ORDER_DATE                           NOT NULL     DATE                               -------NOT NULL约束传递了。
 TEST_UNIQ                                                         NUMBER
 TEST_CHECK                                                     NUMBER

SQL> select table_name,constraint_name,constraint_type,search_condition,r_constraint_name from user_constraints  where table_name='NEW_SALES';

TABLE_NAME                     CONSTRAINT_NAME                C SEARCH_CONDITION                                                                 R_CONSTRAINT_NAME
------------------------------ ------------------------------ - -------------------------------------------------------------------------------- ------------------------------
NEW_SALES                      SYS_C006947                    C "ORDER_DATE" IS NOT NULL

 

本来以为C 是check约束,后来发现,是规定NOT NULL 的。。。。

 

happy结局:NOT NULL 约束在建表的时候会传递。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

丹心明月

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值