• DDL数据定义语句


    DDL语句:create alter rename truncate drop
    1.修改表和约束alter
    create table t_user(
        id number,
        name varchar2(50) constraint user_name_nn not null,
        email varchar2(50),
        gender char(1),
        age number,
        birthday date,
        constraint user_id_pk primary key(id),
        constraint user_email_un unique(email),
        constraint user_gender_ck check(gender in('f','m'))
    );
    alter关键字:
     
      添加新列:
        alter table t_user add birthday date;
      删除一列:
        alter table t_user drop column birthday;
      给列添加约束
        alter table t_user add constraint user_name_un unique(name);
      删除表中的约束
        alter table t_user drop constraint user_name_un ;   
      修改表中某列的类型
        alter table t_user modify (name varchar2(20))
      修改表名(rename关键字仅仅可以修改表名,不可以用来修改列名)
        rename t_user to test;
      使表中的约束失效
        alter table t_user disable constraint user_id_pk cascade;
      让失效的主键再次生效
        alter table t_user enable constraint user_id_pk;
      //这种操作的关键在于,数据是否可以通过验证
      //当表中有数据的的时候,若要启用一个约束,就要先看看该表中的当前数据是否满足这个约束

    alter table 表名
    add     添加新列,给列添加约束
    drop    作用于表,列,约束
    modfiy  作用于表中的某一列 
    disable 作用于约束
    enable  作用于约束
    rename  作用于表

    截取表中的数据(不需要提交,默认已经提交,执行后无法回滚):
      truncate table t_user;
      相当于:
      delete from t_user;
      commit;
     
    注释:
    给表加注释
      comment on table is 'good';
    给列加注释
      comment on column t_user.name is 'good';
    查看表注释    
      select * from user_tab_comments where
      table_name=upper('t_user');
    查看列注释    
      select * from user_col_comments where
      comments is not null;
      and 
      table_name=upper('t_user');

    注意:在使用了DDL语句之后,事务是会提交的。
  • 相关阅读:
    pytest-pyppeteer:在pytest中运行pyppeteer
    ovs学习
    PHP面试(A-01)
    win10桌面美化和使用_壁纸网站
    Typora配置双击图片放大功能
    如何在没有微软商店的情况下在Windows 10上安装应用程序
    springboot多数据源使用EntityManager
    elementui toolTip踩坑记录
    前端算法手动实现数字排序
    linux FTP Connection refused
  • 原文地址:https://www.cnblogs.com/Magic-Li/p/12774844.html
Copyright © 2020-2023  润新知