zoukankan      html  css  js  c++  java
  • oralce10g中约束与列属性NULLABLE的关系

    结论:

    columname type not null与check (columnname is not null)的结果是不一样的

    因此:

    1、不需要手工去匹配NULLABLE属性,当所有显式导致NULLABLE由Y变N的约束被删除后,NULLABLE自然会恢复为Y。

    2、尽量不要使用CHECK来实现NOT NULL,可以使用MODIFY或直接在字段后声明

    drop table zwxtest04;
    create table zwxtest04
    (

     id integer
    );
    alter table zwxtest04 add constraint zwxtest04c2 check (id is not null);
    select * from user_tab_columns where table_name='ZWXTEST04';
    select * from user_constraints where table_name='ZWXTEST04';

    --NULLABLE 为Y ,约束并不会导致NULLABLE变动

    drop table zwxtest04;
    create table zwxtest04
    (

     id integer not null
    );

    select * from user_tab_columns where table_name='ZWXTEST04';
    select * from user_constraints where table_name='ZWXTEST04';

    -- NULLABLE 为N ,同时自动添加一个C型的NOT NULL的约束

    drop table zwxtest04;
    create table zwxtest04
    (

     id integer 

    );
    alter table zwxtest04 id not nul;
    select * from user_tab_columns where table_name='ZWXTEST04';
    select * from user_constraints where table_name='ZWXTEST04';

    -- NULLABLE 为N ,同时自动添加一个C型的NOT NULL的约束

    drop table zwxtest04;
    create table zwxtest04
    (

     id integer
    );
    alter table zwxtest04 add constraint zwxtest04c3 primary key (id  );
    select * from user_tab_columns where table_name='ZWXTEST04';
    select * from user_constraints where table_name='ZWXTEST04';

    -- NULLABLE 为N ,创建P型约束,创建UNIQUE索引

    alter table zwxtest04 drop constraint zwxtest04c3 ;

    --NULLABLE为Y

  • 相关阅读:
    bzoj4195 [Noi2015]程序自动分析
    bzoj4236 JOIOJI hash 模拟
    bzoj1012 [JSOI2008]最大数maxnumber
    day 4 名片管理系统 -函数版
    day 3 局部变量 全局变量
    day 2 函数的嵌套
    day1 函数 (独立功能代码块)
    day 14 元组
    day 13 字典dict 操作
    day 12 列表字典 补充
  • 原文地址:https://www.cnblogs.com/QinQouShui/p/1869950.html
Copyright © 2011-2022 走看看